George Neuner <gneuner2@comcast.net> writes:>C does not allow either duplicate definitions or multiple definitions>of the same named object in any name overloading class (of which the>"top level", ie. global names, is one). You can have duplicated>_declarations_, but not duplicated _definitions_.
...>But for the sake of a discussion about compilers, how would you>handle the situation if it were up to you?

What I expected is that the linker complains about duplicate symbols
(irrespective of optimization level). I was very surprised that GNU
ld produced only warnings for the example given, and that linking
succeeded. I wonder why this does not happen; two explanations come
to mind:

* There are important programs around that use definition syntax
(i.e., no extern) for global variable declarations and C compiler
writers want their compilers to work on these programs.

* There is no good way to let the linker work the way I expect it;
maybe you cannot have strong symbols in the bss segment or something
(although I would find that surprising).

- anton
--
M. Anton Ertl
anton@mips.complang.tuwien.ac.athttp://www.complang.tuwien.ac.at/anton/
[I think it's a historical artifact. The early linkage behavior of C
was based on Fortran COMMON statements, where you could have multiple
uninitialized versions and optionally one initialized (BLOCK DATA)
version. -John]