This is the mail archive of the gcc-help@gcc.gnu.org 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: Global Variables


"Ajay Bansal" <Ajay_Bansal at infosys dot com> writes:

> Hi All
> 
> Has anyone faced problems with global variales intialization. I a facing
> lots of problems in this regard. If I have library initializers, & they
> use some global variables.. Lots of problems happen.
> 
> Anybody else with a similar experience??

Yes. The standard says you can't rely on the order of initialization
    of global variables. Instead:

Foo& foo()
{
    static Foo internal;
    return internal;
}

That way you are guaranteed internal is initialized before its first use.


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