This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Compiling GCC With a C++ Compiler (g++)


"Dave Korn" <dk@artimi.com> writes:

>   The problem was in refactoring a huge amount of legacy code that used a
> vast number of global variables.  To try and modularise and data-hide it
> somewhat I wanted them all to become local to a single module, with accessor
> functions visible to the rest of the application.  So I declared them all
> "extern CONST" in a header file.  When a client module wanted to include the
> header file, it got CONST defined as "const", but when the same header was
> included by the module that instantiated the variables, CONST was defined to
> nothing.  This allowed me to simulate protected class member variables, but
> had the aforementioned consequence on the optimiser.

IMHO this is a rather different situation.  Since the declaration says
const the compiler can assume that the definition also says const (since
they must match), and that the object is really read-only.

On some platforms such a program may even fail to compile because the
method to access read-only objects may be incompatible that of writable
objects.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]