The Standard, 3.6.2, says that such initialization should work, making a few assumptions.
"Objects of POD types (3.9) with static storage duration initialized with constant expressions (5.19) shall be initialized before any dynamic initialization takes place." Therefore, the assignment of 3.14 should happen before any other initialization.
"Objects with static storage duration defined in namespace scope in the same translation unit and dynamically initialized shall be initialized in the order in which their definition appears in the translation unit." Since pi
appears before div
in the definition, it should be initialized first.
I'm assuming that the statements are as you gave them, and that TDouble
is some sort of fancy version of double
. If TDouble
is a class with real behavior, that complicates things. Similarly, you aren't showing the context of the code, or even whether the .h file is #include
d in more than one .c file (in which case you'd have problems with the One Definition Rule). Alternatively, you might not be using a standard-conformant compiler.
So, what's the definition of TDouble
? What's the context for the lines? What compiler are you using, and with which compiler options?
Initialization like this is not good style, partly because minor changes in the code or how you use it can cause bugs, but this should work as far as I can tell.