"Re: Array Initialization - (nf)"
tom at rlgvax.UUCP
tom at rlgvax.UUCP
Sat Jul 9 05:34:13 AEST 1983
The "bible" (i.e. Kernighan & Ritchie's book) states quite clearly on
page 198 of the C Refernce Manual that:
Static and externals that are not initialized are guaranteed
to start off as 0;
There is little room for disagreement. Until there is a C language Standard,
the K & R book is the closest to one we have. When a Standard finally is
developed, I'll give very good odds that this requirement is in there.
In fact, every C compiler specification (contract, product requirement,
etc) that I have seen calls for implementation according to the K & R
book.
So, if it doesn't default initializations to 0, it AIN'T C.
If you are still nervous about portability (I usually am), every variant of
a C compiler that I have seen (at least 12 that I can think of offhand)
does default initialization to 0.
However, it is a good programming practice to do explicit initialization
to 0. The reason is program legibility. If its important that the
initial value be 0, why keep it a secret?
- Tom Beres
{seismo, allegra, mcnc}!rlgvax!tom
More information about the Comp.lang.c
mailing list