6

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?

2
  • 1
    C, or C++? If the former, it's struct Image image[10]; Commented Nov 15, 2011 at 22:16
  • We need to see more code. What is the complete description of the error? Are these structs in the same file? Is the Image before ShapeImage? Etc. Commented Nov 15, 2011 at 22:16

1 Answer 1

16

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.