Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!uw-beaver!tikal!slovax!michael From: michael@slovax.UUCP Newsgroups: comp.lang.c Subject: Re: Initialization of a two-dimen. array of structures. Message-ID: <340@slovax.UUCP> Date: Fri, 20-Mar-87 15:45:31 EST Article-I.D.: slovax.340 Posted: Fri Mar 20 15:45:31 1987 Date-Received: Sun, 22-Mar-87 22:27:44 EST References: <2173@ncoast.UUCP> Distribution: comp Organization: R & D Associates., Tacoma, WA Lines: 62 > I have a structure like this: > =============================== > > struct of_stuff { > char *name > float value; > float another; > int counter; > } > > stuff[20][30] = { > { > "joe", 1, 0, 12, > "fred", 1, 0, 13, > "carol",1, 0, 4 } > , > { > "joe", 1, 0, 12, > "fred", 1, 0, 13, > "carol",1, 0, 4 } > } > > > ... when I tried it on a vax 11/780 running 4.3BSD and a Sun workstation > running whatever they call Unix (the latest 3.0 I believe), I got an error. > > Gregory R. Simpson Ditto here on BSD. It compiled okay with the addition of another level of matching {}: stuff[20][30] = { { {"joe", 1, 0, 12}, {"fred", 1, 0, 13}, {"carol",1, 0, 4} } } K&R p. 124 says, for a particular example, "... It would be more precise to enclose initilizers for each 'row' or structure in braces, ... but the inner braces are not necessary when the initializers are simple variables or character strings, and when all are present." Apparently some compilers prefer the inner braces. It doesn't hurt to have them in either case. Michael Longe' R & D Associates ..!tikal!slovax!michael ------ standard disclaimer ------------------------------------------------- I work in C, and my employers know it. ------ usual exclaimer ----------------------------------------------------- Qui, moi?