static versus auto initialization

K.LAUX rkl1 at hound.UUCP
Fri Jan 20 03:09:43 AEST 1989


In article <8901182125.AA06523 at decwrl.dec.com>, devine at cookie.dec.com (Bob Devine) writes:
) 
)   Would someone explain to me why the discrepancy between the
) uninitialized elements of static and auto arrays?
) 
)   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.  
) 

	Correct.  (What more do you need? :-) ). 

	Unless you want to know that the Static has all elements initialized
at Compile Time and for Auto there is actual code to only initialize the
specified elements, the rest defaulting to whatever was in the memory
allocated for the array.

--rkl



More information about the Comp.lang.c mailing list