This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Bug or feature: symbol names of global/extern variables
>>> Wolfgang Roemer <w.r.a.roemer@t-online.de> 06.10.05 16:02:37 >>>
>On Thu Oct 06, 2005 15:54, Michael Veksler wrote:
>[..]
>>> 2. I think that it will break C. As I remember, it is sometimes
>>> legal in C (or in some dialects of C) to have conflicting
types.
>>> You may define in one translation unit:
>>> char var[5];
>>> and then go on and define in a different translation unit:
>>> char var[10];
>>> The linker will merge both declarations and allocate at least
>>> 10 bytes for 'var' (ld's --warn-common will detect this).
>
>that is interesting: If the linker would behave that way, I wouldn't
get the
>error because the needed 8 bytes for a double would be allocated.
I think your example had the variables initialized; this is a
difference. The linker does behave as Michael described for
uninitialized (aka common) variables; gcc's -fno-common suppresses this
behavior.
Jan