The specific type of initialization that I think you're talking about:
Basically, what I'm asking is does anyone disagree that static simple C types (non-objects) like char, short, int, and long (and structs without constructors composed of those types) are initialized when an executable is loaded into memory, before main() or any other constructor is invoked?
I assume you mean that the initialization with constants - not by calling a function. If that assumption is correct, then yes you can be sure that initialization will happen before any constructors are called:
- 3.6.2 initialization of non-local objects
Objects with static storage duration
(3.7.1) shall be zero-initialized
(8.5) before any other initialization
takes place. Zero-initialization and
initialization with a constant
expression are collectively called
static initialization; all other
initialization is dynamic
initialization. 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.
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.
However an initalization such as
static int x = getvalue();
falls into the dynamic initialization category, so it gets ordered by appearance (and indeterminately between different translation units).
Another caveat is that this doesn't apply to local statics (which might not be initialized until their block is entered), but that really doesn't matter since they aren't accessible to anything else until the enclosing block has been entered anyway.