1

1) Is it true that static data members of classes always get initialized before main() called?

2) Is it true that "static initialization order fiasco" can happen if static data member of class initialization code uses global static variable of other translation unit?

Where can I read more about it? I couldn't find answer in 2003 standard of C++.

Thanks a lot.

1

2 Answers 2

1

1) Is it true that static data members of classes always get initialized before main() called?

yes they would always be initialized before program starts executing.

2) Is it true that "static initialization order fiasco" can happen if static data member of class initialization code uses global static variable of other translation unit?

Yes, along with this it also happens for every other thing which is initialized before main() execution.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes to both answers.

see https://isocpp.org/wiki/faq/ctors#static-init-order for a good description of it.

2 Comments

I've read it, but it is only about static objects, not about static data members of classes. Is it right that in that sense there's no difference between static global objects and static global variable?
static members of classes are nothing more than regular static objects with some syntactic sugar on top (e.g. access specifiers, name visibility). But that's only during compilation. At runtime there's no difference to other static objects.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.