Jun. 16th, 2010
What's the "static initialization order fiasco"?
FAQ: A subtle, frequently misunderstood source of errors, which are hard to catch because they occur before main is called. The errors can happen when the constructor of a global object defined in x.cpp accesses (directly or indirectly) a global object defined in y.cpp. The order of initialization of these objects is undefined, so you'll see the problem in 50% of the cases (an error may be triggered by a rebuild). "It's that simple".
FQA: And it's that stupid. Just look at this:
* C++ doesn't define the order of initialization of global objects.
* C++ lets you write code that depends on the order of initialization of global objects.
* C++ doesn't have a mechanism to automatically detect these errors, neither at compile time nor at run time.
* C++ doesn't make the slightest effort to help you debug the problem (for example, go figure in which actual order the objects were initialized).
FAQ: A subtle, frequently misunderstood source of errors, which are hard to catch because they occur before main is called. The errors can happen when the constructor of a global object defined in x.cpp accesses (directly or indirectly) a global object defined in y.cpp. The order of initialization of these objects is undefined, so you'll see the problem in 50% of the cases (an error may be triggered by a rebuild). "It's that simple".
FQA: And it's that stupid. Just look at this:
* C++ doesn't define the order of initialization of global objects.
* C++ lets you write code that depends on the order of initialization of global objects.
* C++ doesn't have a mechanism to automatically detect these errors, neither at compile time nor at run time.
* C++ doesn't make the slightest effort to help you debug the problem (for example, go figure in which actual order the objects were initialized).