Topic: Order of initialisation


Author: jss@lucid.com (Jerry Schwarz)
Date: Thu, 11 Jun 92 16:57:00 GMT
Raw View
   A::A() : b(c), a(c++) { ... }
|>
|> But the important point in this program is not the order of
|> initialization - it's the order in which the arguments to
|> the initializers are evaluated.  For example, is it legal to
|> do the computations in this order?
|>
|>    1) Evaluate c
|>    2) Evaluate c++
|>    3) Initialize a.a with the result of step 2
|>    4) Initialize a.b with the result of step 1
|>
|> This obeys the restriction from page 292 of the ARM: a.a is
|> initialized before a.b.  But the output of the program would
|> be 0 0 (as produced by gcc).


The ARM does not address this issue.  Indeed, it does not
address any of the issues that are addressed by the notion
of "sequence point" that was introduced by the C standard.

There have been discussions of this issue by X3J16 members
and the concensus is that there should be "sequence points" before
each construction/initialization occurs. What this means is that only
legal order would be

 1. Evalauate c++, including it's side effect
 2. Construct a with result of 1
 3. Evaluate c
 4. Construct b with the result of 2

However, X3J16 as a whole has not yet officially adopted
any position with regard to sequence points in general or this
matter in particular, so no definitive answer is possible.

   -- Jerry Schwarz