Mail Archives: djgpp/1996/10/10/05:57:46
A.Appleyard wrote:
>
> This program:-
>
> 1 #include<stdio.h>
> 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 <stdio.h>
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
- Raw text -