Newsgroups: comp.os.msdos.djgpp From: design AT netcom DOT com (Chris Waters) Subject: Re: Labelled array display element funny Message-ID: Organization: Design and Delivery References: <7E03B4350B AT fs2 DOT mt DOT umist DOT ac DOT uk> <53gjj8$5l7 AT mark DOT ucdavis DOT edu> Date: Wed, 9 Oct 1996 21:15:43 GMT Lines: 53 Sender: design AT netcom4 DOT netcom DOT com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <53gjj8$5l7 AT mark DOT ucdavis DOT edu>, Jeffrey Taylor wrote: >A.Appleyard (A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk) wrote: >: This program:- >: >: 1 #include >: 2 typedef struct{char *codeno; char*name;} craft; >: 3 craft dsub[128]={ >: 4 [1] {"CH79","Aphanistor"}, >: 5 [55] {"DS1 ","Quackers"}, >: 6 [56] {"DS2 ","Donald"}, >: 7 [23] {"BA32","Big Jim"}, >: 8 [35] {"FA65","Trelawney"}}; >: 9 main(){} >: >: produced these errors:- >: t$.cc:5: parse error before `[' >: t$.cc:5: warning: aggregate has a partly bracketed initializer >: t$.cc:6: parse error before `[' >: >: What have I done wrong here? Or can't I use array element labels when the >: elements are subarray displays? > >Correct. You cannot use array labels in C initializers. Unless you're using gcc. And gee, guess what? :) The correct answer is that if you have an array of structures, you must name the structure fields in your initializers: craft dsub[128]={ [1] {codeno: "CH79", name: "Aphanistor"}, [55] {codeno: "DS1 ", name: "Quackers"}, [56] {codeno: "DS2 ", name: "Donald"}, [23] {codeno: "BA32", name: "Big Jim"}, [35] {codeno: "FA65", name: "Trelawney"}}; And in the future, if you have gcc-specific questions, I recommend asking on one of the gnu newsgroups (gnu.gcc.*). The djgpp people are great with questions about accessing DPMI from gcc and other DOS related stuff, but, as I think you can tell, they don't support or maintain gcc directly--they simply use whatever the GNU folks provide. Of course, one could hope that they would look through the info files provided with gcc (which is where I found the answer above). But then, you might have tried the same thing, rather than asking people who mostly didn't have any idea of what you were talking about. Did I mention that what you're doing is not portable to any compilers besides gcc? (Of course, that's not much of a limitation, since gcc runs on just about everything.) And just how _did_ you figure out that you could do that without figuring out how to do it correctly? Inquiring minds want to know. :)