This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Global Variables
- From: LLeweLLyn Reese <llewelly at lifesupport dot shutdown dot com>
- To: "Ajay Bansal" <Ajay_Bansal at infosys dot com>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: 06 Mar 2003 21:18:02 -0800
- Subject: Re: Global Variables
- References: <2B721C6525F0D411B1E900B0D0226BDD0214911C@mohmsg01.ad.infosys.com>
- Reply-to: gcc-help at gcc dot gnu dot org
"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.