I have a program where I use cout to emit debug information. The code is executed in the initialization of a static global variable, i.e. quite early in the program execution. W
std::cout
is an object in static storage. It's guaranteed to be initialized before entering main
, but not necessarily before other statics in your code. Seems like the static initialization order fiasco.
After some digging:
Init ();
3) Effects: Constructs an object of class Init. If init_cnt is zero, the function stores the value one in init_- cnt , then constructs and initializes the objects cin, cout, cerr, clog (27.3.1), wcin, wcout, wcerr, and wclog (27.3.2). In any case, the function then adds one to the value stored in init_cnt .