Does extern "const" allocate storage?
Robert Lenoil
lenoil at Apple.COM
Thu Mar 17 09:24:24 AEST 1988
I'm having some trouble understanding the const type qualifier. If I declare
const int foo = 3;
then I hope that the compiler would actually use the constant 3 whenever foo
is used, instead of allocating storage and generating a reference to foo.
One exception, however, would be if I declare
const int *bar = foo;
which would have to allocate storage for foo so that a pointer to foo could be
placed in bar. My question involves what happens when foo is defined in
another module? Does
extern const int foo;
expect to be linking to an external constant, or is it linking to an external
integer, and semantically prohibiting assignment to that integer? If the
latter is true, then every file with an extern reference to foo would have to
reference foo wherever it is used, instead of using a constant. In this case,
using const would be less efficient than #define. What about
extern const char foo[];
I suppose that's illegal, because sizeof(foo), which should be a constant,
won't work. The ANSI C draft of 1/11/88 mentions the const type qualifier
in section 3.5.3 but doesn't actually define its meaning. And while we're
discussing that section, can someone translate their definition of noalias
into English for me? (If you thought reference manuals are hard to follow,
just try the ANSI draft on for size.)
Robert Lenoil
More information about the Comp.lang.c
mailing list