Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.lang.c Subject: Re: static versus auto initialization Message-ID: <867@auspex.UUCP> Date: 19 Jan 89 18:50:54 GMT References: <8901182125.AA06523@decwrl.dec.com> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 61 > 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". If "D.R." stands for Dennis Ritchie, I don't think he ever specified or implemented initialization of automatic aggregates, period. I know PCC doesn't implement it as it comes out of the box. K&R Second Edition says: The first edition did not countenance initialization of automatic structures, unions, or arrays. The ANSI standard allows it, but only by constant constructions unless the initializer can be expressed by a simple expression. I guess the latter part means you can do struct foo { int a; int b; }; static const struct foo foobar = { 666, 666 }; void func(void) { struct foo bletch = foobar; ... } The May 13, 1988 draft specifically says that you can initialize automatic structures and unions with a non-constant simple expression, but doesn't mention arrays, which makes sense since you can't do array assignment. Presumably, the compiler in your example is one that implements initialization of automatic aggregates: > 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. I consider this bogus. The May 13, 1988 dpANS seems to agree: If there are fewer initializers in a list than there are members of an aggregate, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration. with no qualifiers indicating that this applies only to static aggregates. If your compiler purports to conform to some draft of the C standard, it's not the May 13, 1988 draft....