Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc compile error on simple code

Tags:

c

gcc

compilation

I need help with a simple c structure and can't find it why it's not compiling using gcc (opensuse 11.4)

I have this code:

struct Image {
 int w;
 int h;
 // other code
};

in the same file I have another struct array like this:

struct ShapeImage
{
  Image image[10];
  // other code
};

when I compile I get:

syntax error before [' token`

Why I am getting this error if is specify the number 10 in the image the image[10]; looks good to me, what is wrong?

like image 526
joel Avatar asked Nov 15 '11 22:11

joel


1 Answers

It should be:

struct Image image[10] ;

Or use typedef while defining the struct:

typedef struct {
 int w;
 int h;
 // other code
} Image;

And use the code otherwise same as in your question.

like image 171
Aditya Naidu Avatar answered Nov 05 '22 21:11

Aditya Naidu