On Nov 18, 8:28 pm, Craig Scott <audiofana...@gmail.comwrote:
Quote:
On Nov 18, 10:24 pm, James Kanze <james.ka...@gmail.comwrote:
Quote:
On Nov 17, 8:52 pm, Craig Scott <audiofana...@gmail.comwrote:
Quote:
I think my original post does not sufficiently address the
situation of a POD type initialized with a constant expression
and I would like to fill in the gaps.
Quote:
Quote:
You're post really neglects reality. The constraints that the
standard imposes if dynamic initialization is deferred until
after main are impossible to meet, and no implementation tries.
(Dynamic linking may open up another can of worms, but what
happens then is implementation defined anyway---although most
systems behave identically here as well.) From a practical
point of view, it's safe to say: zero initialization, then
static initialization, then dynamic initialization, then main.
With the first occasion for your code to run being dynamic
initialization (which means that the zero initialization of
statically initialized objects isn't visible, and may be
skipped).
Quote:
Quote:
There's also, of course, the fact that many, many idioms depend
on dynamic initialization before main, and that any compiler
which tried to do otherwise simply wouldn't be used.
Quote:
I assume you are excluding local static objects here,
Obviously, since they do have a (somewhat) different lifetime.
According to the standard, the constructor may not be called
until the first time the object comes into scope (and should
never be called if the object never comes into scope).
Quote:
since it is easy to verify that at least one very popular
compiler delays initialization of local statics until the
first call of the function in which it resides (as I expect
most compilers probably do too).
Given that it's required by the standard.
I should have been clearer: I was talking about the
initialization described in §3.6.2: Initialization of non-local
objects. But the standard seems to halfway merge the two: the
first sentence of this sections reads "Objects with static
storage duration (3.7.1) shall be zero-initialized (8.5) before
any other initialization takes place." No "non-local" about it.
In general: zero-initialization and constant initialization take
place for all objects with static lifetime, before any dynamic
initialization takes place. Then, in practice at least, dynamic
initialization of non-local, statically linked statics takes
place, and then main is called.
In the case of dynamic linking, the exact same procedure is
applied to the dynamically linked object (except that there is
no main to be called), before returning from whatever system
function loads the dynamic object. At least today.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34