[Info-vax] Possible C compiler static variable initialization problem.
glen herrmannsfeldt
gah at ugcs.caltech.edu
Wed Feb 26 22:05:24 EST 2014
Simon Clubley <clubley at remove_me.eisner.decus.org-earth.ufp> wrote:
> On 2014-02-26, David Froble <davef at tsoft-inc.com> wrote:
(snip)
>> 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.
Yes, C requires that exactly one define and initialize (not have extern)
the variable. The rest should have extern on them. There are linkers
that will complain if all have extern.
However Fortran allows for COMMON blocks, or the equivalent in the
newer standard versions, without initializing the variables.
That is, either zero or one module should initialize the variable.
For systems that allow for both Fortran and C (and maybe also mixed)
both ways have to be allowed.
> 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.
I am not sure, either.
-- glen
More information about the Info-vax
mailing list