[Info-vax] Possible C compiler static variable initialization problem.
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Wed Feb 26 20:26:36 EST 2014
On 2014-02-26, David Froble <davef at tsoft-inc.com> wrote:
> 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.
>>
>
> I'm so confused .... familiar territory for me ...
>
> Is this discussion about multiple modules (think PSECT), or is it about
> multiple source files fed to a compiler to form a single module ????
Neither. :-)
It's about multiple object modules each containing the same definition
of a C variable defined at file level (ie: outside of a function)
within the source file which was used to generate the object module.
When using gcc/binutils, the multiple definitions will be merged into
one variable during linking (unless -fno-common is used as hb just
pointed out).
In the other earlier environment I vaguely remembered, you would
either get the same variable allocated twice or a multiple allocation
error message during linking. It's long enough ago that I cannot
remember for sure which failure mode it was now I have thought more
about it.
Regardless, I thought it was on VMS, but I am no longer sure.
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