Can I safely assume that all static variables are initialized as NULL
or zero, depending on the types of the variables, no matter on which
platform that app is compiled ?
IIRC, the final C99 standard didn't change from the draft, and the draft says:
If an object that has static storage duration is not initialized explicitly,
then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according
to these rules;
— if it is a union, the first named member is initialized (recursively)
according to these rules.
If a compiler doesn't follow these rules, then it is in error. That's not to say
that all compilers follow the rules, though.
--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employers')