gcc在简单代码上编译错误

时间:2011-11-15 22:14:16

标签: c gcc compilation

我需要一个简单的c结构的帮助,但无法找到它为什么不使用gcc进行编译(opensuse 11.4)

我有这段代码:

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

在同一个文件中我有另一个结构数组,如下所示:

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

当我编译时,我得到:

syntax error before [' token`

如果在图像中指定数字10,为什么会出现此错误 image[10];看起来对我好,有什么不对?

1 个答案:

答案 0 :(得分:16)

应该是:

struct Image image[10] ;

或者在定义struct时使用typedef:

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

并使用与您的问题相同的代码。

相关问题