Victor Bazarov wrote:
Joseph Turian wrote: When does initialization of static member variables occur?
At some point before 'main' is called, if they are defined.
In the following code fragment, is m_start_time automatically
initialized right before main()?
Yes.
Not necessarily. It is certain that m_start_time will be
zero-iniitalized before main() executes. But since m_start_time is not
initialized with a constant expression, its initialization is dynamic,
not static. §3.6.2/1. Therefore, it is implementation-defined whether
m_start_time will be initialized before main() is called. In other
words, your compiler documentation will have the answer to this
question.
[This is the desired effect.]
Or is m_start_time uninitialized until the first time I use a static
method in stats?
No.
Possibly. It is certain that m_start_time will be completely
initialized before the first use of any object or function in its
translation unit (i.e. source file) §3.6.2/3. Of course such use could
occur well after the program has started.
Greg