This is specified by C++11 3.6.2: constant initialization is performed...
if an object with static or thread storage duration is not initialized by a constructor call and if every full-expression that appears in its initializer is a constant expression.
This is your situation, except for d
: int
and float
don't have constructors, and the initializer is a literal, which is a constant expression. Constant initialization is part of static initialization, and:
Static initialization shall be performed before any dynamic initialization takes place.
The standard doesn't explicitly prescribe an implementation, but there is no ordering of static initializations, and it is understood that the initial values are essentially provided at load time, and no code executes in order to get those global variables to have their initial values.
The variable d
does not meet these criteria since its initializer is not a constant expression (because c
is not a constant expression). The standard allows d
to be initialized either dynamically or statically.