Boost logo

Boost :

Subject: Re: [boost] Any interest in static plugins?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-12-16 17:11:29

On Wed, Dec 16, 2009 at 1:55 PM, Dave van Soest <dsoest_at_[hidden]> wrote:
> Hi all,
> The C++ standards document states that it is implementation dependent
> whether the constructor of a static object is called before entering main()
> or just before first use (ISO/IEC 14882:2003 section 3.6.2 part 3).
> I can't help wondering why the standard leaves this choice open to
> implementation.

The idea is to allow for costly initializations to be postponed until
they are actually needed. For example, if a static object allocates a
gig of RAM, that would be wasteful if the static object isn't needed
in a particular run of the program.

> The compilers/linkers/platforms I tested my library with all enable calling
> the constructors before entering main() by default, but this behavior is not
> guaranteed by the language. I currently don't know whether this behavior can
> be guaranteed in any way. If so, the library may still be useful, but
> perhaps not for Boost.

No, the behavior can not be guaranteed. What's more, static objects,
along with all relevant code, can be deadstripped unless you
explicitly call a function from their translation unit (cpp file.)

Emil Dotchevski
Reverge Studios, Inc.

Boost list run by bdawes at, gregod at, cpdaniel at, john at