Static initialization order

Ali Çehreli acehreli at yahoo.com
Sun Feb 7 08:35:33 PST 2010


Justin Johansson wrote:
 > Walter Bright wrote:
 >> Justin Johansson wrote:
 >>> May I ask, what are the best solutions for C++ (my current
 >>> dilemma) and what steps will be taken in D2 to zap it.
 >>
 >> Within a module, static initialization is done in lexical order.
 >>
 >> Across modules, static initialization is performed so that imported
 >> modules are initialized before the importer.
 >>
 >> This is true in D1 as well as D2.
 >
 > Thanks for the clarification for both D1 and D2.  Certainly D's approach
 > beats the hit-and-miss approach in C++.

That's unfortunate and has been many causes of bugs for C++ programs.

C++ follows C's model of separate compilation. The C++ compiler never 
sees more than one translation unit (a source file after all 
preprocessor magic applied to it) at a time.

The best C++ could do was to define the order in that single translation 
unit; and that is the same order as D's.

Ali



More information about the Digitalmars-d mailing list