|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-12-16 17:18:43
"Martin Bonner" <martin.bonner_at_[hidden]> writes:
> Emil Dotchevski wrote:
>> 3.6.2.3: 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
>> done before the first statement of main. If the initialization is deferred
>> to some point in time after the first statement of main, it shall occur
>> before the first use of any function or object defined in the same
>> translation unit as the object to be initialized.
>
> Yes, but I think you will find that unless the implementation /does/
> perform dynamic initialization before the first statement of main,
> it will have unsolvable ordering problems.
You can have unsolvable ordering problems anyway. That's the whole
reason for the Meyers Singleton.
> Consider a class A
> defined in a.cpp, and B defined in b.cpp.
>
> a.cpp:
> extern B theB;
> A::A() { .... }
>
> b.cpp:
> extern A theA;
> B::B() { .... }
>
> Now then. If something from a.cpp is referenced externally then the
> compiler must initialize 'theB' before it starts using any of the
> functions in a.cpp.
Not according to the standard. Why do you say it "must?"
>>> As far as "deadstripping" code - this has indeed been a big
>>> problem - especially in release mode. I've referred to it as
>>> overzealous optimization.
>
>> It isn't overzealous -- it's within the specifications of the
>> standard, whether you like it or not.
>
> Chapter and verse? (Given the above argument that dynamic
> initialization must happen first.)
Completely unrelated, even if your argument about ordering didn't have
holes in it. Even if it is a fact that event X cannot follow event Y,
there's still no reason event X has to happen at all.
-- 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