Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utfyzx!sq!msb From: msb@sq.UUCP Newsgroups: comp.lang.c Subject: Re: Initialization of a two-dimen. array of structures. Message-ID: <1987Mar25.160850.6571@sq.uucp> Date: Wed, 25-Mar-87 16:08:50 EST Article-I.D.: sq.1987Mar25.160850.6571 Posted: Wed Mar 25 16:08:50 1987 Date-Received: Sat, 28-Mar-87 01:14:33 EST References: <2173@ncoast.UUCP> <340@slovax.UUCP> <1497@dg_rtp.UUCP> Reply-To: msb@sq.UUCP (Mark Brader) Distribution: comp Organization: SoftQuad Inc., Toronto Lines: 53 Checksum: 31830 > The draft ANSI standard says it is implementation defined what > happens if you have left some intermediate level of braces off. Nope, at least not the October 1986 (public comment) draft. Some earlier ones said only that this would be resolved in a later draft; perhaps still earlier ones said it was implementation dependent. a From section 3.5.6, page 62 (lines 3-17): # An array of characters may be initialized by a string literal, # optionally enclosed in braces. Successive characters of the # string literal (including the terminating null character if there # is room or if no size for the array is specified) initialize the # members of the array. # # Otherwise, the initializer for an object that has aggregate type # shall be a brace-enclosed list of initializers for the members of # the aggregate, written in increasing subscript or member order. # # If the aggregate contains members that are aggregates, the rules # apply recursively to the subaggregates. If the initializer of a # subaggregate begins with a left brace, the succeeding initializers # initialize the members of the subaggregate. Otherwise, only enough # initializers from the list are taken to account for the members of # the first subaggregate; any remaining initializers are left to # initialize the next member of the subaggregate of which the current # aggregate is a part. # # 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 duration. I think the above is almost incomprehensible without careful study, but the example at lines 42-25 of the same page makes things clear: # struct { int a[3], b; } w[] = { { 1 }, 2 }; # # is a definition with a partly bracketed initialization, which is # not recommended programming practice. It defines an array with two # member structures: w[0].a[0] is 1 and w[1].a[0] is 2; all the other # elements are zero. That is, the above is equivalent to: struct { ... } w[] = { { { 1 } }, { { 2 } } }; and therefore to struct { ... } w[] = { {{1,0,0}, 0}, {{2,0,0}, 0} }; Mark Brader, utzoo!sq!msb C unions never strike!