Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ll-xn!cullvax!drw From: drw@cullvax.UUCP (Dale Worley) Newsgroups: comp.lang.c Subject: possible structure initialization bug Message-ID: <1458@cullvax.UUCP> Date: Thu, 13-Aug-87 11:19:22 EDT Article-I.D.: cullvax.1458 Posted: Thu Aug 13 11:19:22 1987 Date-Received: Sat, 15-Aug-87 09:06:16 EDT Organization: Cullinet Software, Westwood, MA, USA Lines: 51 fnf@mcdsun.UUCP (Fred Fish) writes: # [Is the following construction valid?] # # struct { # int foo[2][2]; # } bar = { # {1, 2, 3, 4} # }; # # [Notes that the initializer "{{1, 2}, {3, 4}}" is # preferred for portability in pre-ANSI systems.] # [The following is from 3.5.6 of the Draft:] # * "... 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 sub- # * aggregate 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." It seems to be that the last clause has a typo; it should read "...the next member of the *aggregate* of which the current *subaggregate* is a part". Otherwise it doesn't make sense. My reading is that if a subaggregate initializer (in this case, for the two subordinate arrays) doesn't start off with a '{', then it just draws the proper number of elements from the list and the remainder of the list initializes elements of the top-level aggregate. What you wrote should work, because you are initializing a "structure with a field which is an array of arrays of integers". The initializers break down: object initializer bar { { 1, 2, 3, 4 } } bar.foo { 1, 2, 3, 4 } At this point, we invoke the "if the initializer for a subaggregate does not begin with a left brace rule", and the elements bar.foo[*][*] get initialized like you'd expect. Dale -- Dale Worley Cullinet Software ARPA: cullvax!drw@eddie.mit.edu UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw OS/2: Yesterday's software tomorrow Nuclear war? There goes my career!