"const" globals are being handled as "static const" globals?
Manfred Hollstein
manfred@s-direktnet.de
Thu May 14 12:40:00 GMT 1998
On Thu, 14 May 1998, 13:51:12, bgarcia@fore.com wrote:
>
> If you define a variable within a file (global) like:
>
> const int foo = 1;
>
> and compile it, you will find that egcs does _not_ give it global scope:
>
> > nm a.o
> 00000000 r foo
>
> That is, it is treating "foo" as a "static const" instead of just "const".
> Removing the const gives the correct behavior:
>
> > nm a.o
> 00000000 D foo
>
> But then it isn't placed into a read-only section.
egcs is correct in doing it this way. The C++ standard is different
from ANSI-C with regard to const's. If you want your const to get
extern linkage, you need to define it as "extern":
$ cat t.cc
extern const int foo = 1;
$ /tools/gnu/packages/egcs/19980501/bin/gcc -c t.cc
$ nm t.o
00000000 ? __FRAME_BEGIN__
00000000 R foo
00000000 t gcc2_compiled.
Like it, or not ;-)
--
Manfred Hollstein If you have any questions about GNU software:
Hindenburgstr. 13/1 < mailto:manfred@s-direktnet.de >
75446 Wiernsheim, FRG < http://www.s-direktnet.de/HomePages/manfred/ >
PGP key: < http://www.s-direktnet.de/HomePages/manfred/manfred.asc >
More information about the Gcc-bugs
mailing list