Message-ID: <325CC5B6.7DAD@pobox.oleane.com> Date: Thu, 10 Oct 1996 11:45:26 +0200 From: Francois Charton Organization: CCMSA MIME-Version: 1.0 To: "A.Appleyard" CC: djgpp AT delorie DOT com Subject: Re: Labelled array display element funny References: <7E03B4350B AT fs2 DOT mt DOT umist DOT ac DOT uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit A.Appleyard 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? Hi, I just tried the following program (which should bomb in the same way as yours): #include struct newstruct{char name[8];char oname[8];}; void main(void) { int i; struct newstruct mydata[10]={ [2] {"aaaa","eeee"}, [5] {"iiii","oooo"}}; for(i=0;i<10;i++) printf("%d %s %s\n",i,mydata[i].name,mydata[i].oname); } Which compiled ok and ran allright (I also tried the two other solutions proposed on the newsgroup : [2]={}, and [2]{name:"aaaa"....}, they also worked...). This seems to mean that your problem is elsewhere : I compiled it as a C program, but the file extensions you use seem to prove you are compiling a C++ program. A possible explanation to your bug would then be that the array label initialisers only work in C programs, and not in C++. Regards, Francois