There appears to be no easy answer to this, but are there any assumptions that can be safely made about when a static class field can be accessed?
EDIT: The only safe assumption seems to be that all statics are initialized before the program commences (call to main
). So, as long as I don't reference statics from other static initialization code, I should have nothing to worry about?
Best Answer
The standard guarantees two things - that objects defined in the same translation unit (usually it means .cpp file) are initialized in order of their definitions (not declarations):
3.6.2
The other guaranteed thing is that initialization of static objects from a translation unit will be done before use of any object or function from this translation unit:
Nothing else i guaranteed (especially order of initialization of objects defined in different translation units is implementation defined).
EDIT As pointed in Suma's comment, it is also guaranteed that they are initialized beforemain
is entered.