[Info-vax] Possible C compiler static variable initialization problem.
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Wed Feb 26 20:17:21 EST 2014
On 2014-02-26, hb <end.of at inter.net> wrote:
> On 02/26/2014 07:40 PM, Simon Clubley wrote:
>> PS: I've just tried it on Linux and binutils merged the two definitions
>> for "unsigned long int a;" in different source files together without
>> error just as expected and my test program treated them as one variable.
>
> It depends on gcc's extern model, which is common by default. Try to
> compile your example with - fno-common.
Interesting, thanks.
I like to write code whose meaning is obvious from just looking at the
source code itself instead of having to look at the build environment
as well, so I never really go looking for options like that.
What that also means is that when I became aware that not all compilers
and linkers treated multiple definitions of variables across source files
in the same way, I just made it a point to try and write code which
behaved the same way across all environments so I try to define a
variable once and then use extern for everything else, even when using
binutils/gcc.
Simon.
--
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
More information about the Info-vax
mailing list