【发布时间】:2016-02-04 05:42:34
【问题描述】:
我在 C 中有一个结构声明,看起来像这样:
static struct {
int a;
int b;
} myStruct[10];
我想在myStruct中声明一个struct成员变量,所以我尝试添加这个:
static struct {
int c;
int d;
struct myStruct[10] s;
} myNestedStruct[100];
我遇到了一堆错误,即syntax error before or at: [ 和
syntax requires ";" after last struct/union member。实现嵌套结构的更好方法是什么?
编辑:我的代码现在看起来像这样:
static struct {
int a;
int b;
} myStruct[10];
static struct {
int c;
int d;
struct myStruct s[10];
} myNestedStruct[100];
但是我收到一个错误:incomplete struct/union/enum myStruct: s
【问题讨论】:
-
在结构成员中使用“struct myStruct s[10]”。
-
修改
struct myStruct[10] s;为struct myStruct s[10]; -
第二个结构被稍微编辑添加它的名字
myNestedStruct[100]。我进行了更改,但出现了一个错误,上面写着incomplete struct/union/enum myStruct: s -
两个结构都没有标签。在这两种情况下,您都将变量声明为匿名结构。
标签: c