Simen kjaeraas:
> The former could be seen as bad style,
I think this is the relevant passage from the C Standard:
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 [plain old data] 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. [Note:8.5.1 describes the order in which aggregate members
are initialized. The initial- ization of local static objects is described in
6.7.]
So I think a C program that relies on having global floating point
variables/arrays initialized to zero is formally correct.
> but certainly something someone would do.
In one of my D programs translated from C I have had to track down a not easy
to find D1 bug (see enhancement request 4580) caused by the C code assuming
global floating point values set to zero (in D2 signalling NaN may help track
down such bugs).
Bye,
bearophile