static initialization order fiasco

Pages: 12
@webJose - to catch SIOF in action, you need to put classOne and classTwo into separate modules (different .cpp files)

in fact, it's exactly Lines 18, 19, 40, and 41 sitting in two separate .cpp files that can cause the indeterminate order of initialization

the rules are:

1. if the code is in the same module (.cpp), initialization will occur from the first line to the last, ignoring any statics inside of methods or functions (those occur during the first call)

2. if the code is in separate modules and in module scope, initialization occurs in an indeterminate order between the two modules (eg could be a.cpp first and then b.cpp or vice versa)
Last edited on
Topic archived. No new replies allowed.
Pages: 12