On 28/01/2019 16:58, Bernhard Schommer wrote:
> Hi,
> 
> I would like to know if the handling of the option -fno-common has
> changed between version 7.3 and 8.2 for x86. I tried it with the
> default system version of OpenSUSE and for example:
> 
> const int i;
> 
> is placed in the .bss section. With a newer self-compiled version 8.2
> the same variable is placed in the section .rodata. I could not find
> any information in the Changelog whether the behavior has changed and
> thus would like to know if there was any change.
> 

(I think this should be on gcc-help, not gcc.)

"const int i;" is (in C) a tentative definition of an object "i" with
external linkage.  If you don't give an initialiser later in the file,
it is equivalent to "const int i = 0;".  The compiler knows it cannot
legally change or be anything other than 0, and can therefore put it in
the .rodata section.  If you have another "const int i" definition in
another translation unit, you can expect a linker error.

It seems that gcc 7 put this in .bss.  This is equally legal for the
compiler.  There should be no difference in how your code works, unless
you are breaking some other C rules along the way.


But there is no reason why you should ever write a line "const int i;".
 A "const" definition should always have an initialiser - while this
line does the same job as "const int i = 0;" as far as the language is
concerned, it is usually considered better style to initialise const
data explicitly.

So yes, it looks like the handling of this line has changed between
versions of the compiler.  But it should not affect your code functionality.

Reply via email to