http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48127

--- Comment #3 from Dmitry Gorbachev <d.g.gorbachev at gmail dot com> 
2011-03-15 18:00:23 UTC ---
I do not agree that the testcase is invalid. As the standart says:

  Common extensions

  Multiple external definitions

     There may be more than one external definition for the identifier of
  an object, with or without the explicit use of the keyword extern; if
  the definitions disagree, or more than one is initialized, the behavior
  is undefined.

According to the Binutils documentation,

  The linker turns a common symbol into a declaration, if there is a
  definition of the same variable.

Also, from Ian Lance Taylor's article [1]:

  5. If A is a strong definition in an object file:

    * If B is a common symbol, then we treat B as an undefined reference.

I think it would be better to fix this problem in the linker. Gold does not
even warn about it!

However, I don't understand why GCC makes baz[8] to have 32 bytes alignment,
while baz[4] has only 4 bytes alignment. It seems to be a GCC bug.

When baz is declared extern in main.c, the generated code is correct, but less
optimal.


1. http://www.airs.com/blog/archives/49

Reply via email to