Path: utzoo!attcan!uunet!lll-winken!ames!pasteur!ucbvax!decwrl!cookie.dec.com!devine From: devine@cookie.dec.com (Bob Devine) Newsgroups: comp.lang.c Subject: static versus auto initialization Message-ID: <8901182125.AA06523@decwrl.dec.com> Date: 18 Jan 89 18:15:00 GMT Organization: Digital Equipment Corporation Lines: 24 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