From: | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
Newsgroups: | comp.compilers |
Date: | Mon, 25 May 2009 18:01:21 GMT |
Organization: | Institut fuer Computersprachen, Technische Universitaet Wien |
References: | 09-04-072 09-04-086 09-05-010 09-05-022 09-05-028 09-05-038 09-05-039 09-05-050 09-05-055 09-05-065 09-05-069 09-05-073 09-05-087 09-05-110 |
Keywords: | optimize, linker |
Posted-Date: | 25 May 2009 19:50:36 EDT |
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.at
http://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]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.