delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/10/05:57:46

Message-ID: <325CC5B6.7DAD@pobox.oleane.com>
Date: Thu, 10 Oct 1996 11:45:26 +0200
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
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>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019