joel
joel

Reputation: 1034

gcc compile error on simple code

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?

Upvotes: 6

Views: 237

Answers (1)

Aditya Naidu
Aditya Naidu

Reputation: 1380

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.

Upvotes: 16

Related Questions