From: David Abrahams (dave_at_[hidden])
Date: 2006-12-15 19:07:29
"Emil Dotchevski" <emildotchevski_at_[hidden]> writes:
>>> Therefore, you are still prone to threading problems. There is
>>> nothing in the C++ standard which guarantees globals will be
>>> initialized before main().
>> According to the reference I use: The C++ Programming Language by
>> Stroustrup page 244 10.4.9:
>> "A global, namespace or class static object which is created once "at the
>> start of the program" and destroyed at once at the termination of the
>> program." I've always interpreted this to mean what it says and this is
>> reflected in the standard.
You should use the standard rather than TC++PL for this sort of thing;
only the standard is a definitive reference.
>> But I'm sure some else on this list can give
>> a definitive answer as to what the standard actually says.
> 22.214.171.124: It is implementation-defined whether or not the dynamic
> initialization (8.5, 9.4, 12.1, 12.6.1) of an object of namespace scope is
Emil, I agree 100% with everything you write here, but especially
> If there is a consensus that it is desirable to provide for
> automatic dynamic initialization of namespace-scope objects even if
> no function from their compilation unit is ever executed, perhaps
> this needs to be separated in a boost library of its own, as a first
> step of (possibly) adding such feature to the C++ standard.
Yes, that's an important thing to have in many cases, and I wish we
had a portable way of doing it in C++. A Boost library (if such a
thing is possible) would be a great step.
>> I'm not going to disagree with that. This was the first method I used and
>> it works well and is portable. But the lack of an automatic method like
>> "export" raised a chorus of howls which had to be addressed.
> I've seen many instances of chorus of howls from folks that write
> sub-standard code and complain that it isn't working as they have hoped. I
> tend to quote the C++ standard in response.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk