This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Order of initialization of global/static variables

On 29 April 2014 16:25, Yaron Dayagi wrote:
> Hello,
> In gcc 4.4.6 we had no problem with the order of initialization.
> In gcc 4.7.2 we do have a problem.
> A CPP file defined GlobalObj_1 (declared extern in the H file):
> CMyClass GlobalObj_1.
> Another CPP file declared GlobalObj_2 (also declared extern in the H
> file).=  The CPP file used copy constructor:
> CMyClass GlobalObj_2(GlobalObj_1).
> In 4.4.6 GlobalObj_1 was initialized first. Now GlobalObj_2 is
> initialized = first.
> Is this intentional?
> How do I revert to old behavior?
> The problem is that we have many files with many global variables (const).

This question is inappropriate on this mailing list, which is for
discussing development of GCC, not for help using it.  Please take any
follow-up to the gcc-help mailing list instead.

The order of initialization between separate files is not defined, so
your program has a bug and only worked by chance with earlier
versions. See the documentation for the init_priority attribute at for a
non-portable way to control the order.

(Please send any replies to the gcc-help list not this one, thanks).

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]