This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: does g++ delay initializing static local variables?
- From: Ian Lance Taylor <iant at google dot com>
- To: Brendan Miller <catphive at catphive dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 10 May 2011 21:22:18 -0700
- Subject: Re: does g++ delay initializing static local variables?
- References: <BANLkTi=cJbDHrBTDaDyR5AeRGja9tL99ug@mail.gmail.com>
Brendan Miller <catphive@catphive.net> writes:
> Say I have a C++ function like this:
>
> void my_function() {
> static int x = 0;
> }
>
> Then will initialization of x to 0 be delayed until the first call of
> the function? The ABI spec talks about that here:
> http://www.codesourcery.com/public/cxx-abi/abi.html#once-ctor
>
> I was unclear whether this only applies to objects with constructors,
> or whether it also applies to POD initialized with a constant, as
> above.
It only applies to objects which are dynamically initialized, with a
constructor or with a non-constant initial value. It does not apply to
something like your example above, in which a POD is initialized with a
constant.
Ian