static versus auto initialization
Bob Devine
devine at cookie.dec.com
Thu Jan 19 04:15:00 AEST 1989
Would someone explain to me why the discrepancy between the
uninitialized elements of static and auto arrays? Someone in
our group asked me a question on this point and the best answer
that I could generate was, in essence, "Cuz D.R. did it for speed".
The problem looks like this:
static char abc_static [5] = { 'a', 'b', 'c' };
main()
{
auto char abc_auto [5] = { 'a', 'b', 'c' };
. . .
}
For `abc_static', elements [3] and [4] are guarenteed to be zeroed
out. However, for `abc_auto', the same elements are garbage.
You can probably see that he initially had the static version and
was relying upon the zeros, so when he moved the array inside a
function he got burned...
Bob Devine
More information about the Comp.lang.c
mailing list