[英]C struct, incomplete field type
A snippet of my struct declaration: 我的结构声明的片段:
struct record{
char type[4];
uint32_t data_size;
uint32_t flags;
uint32_t id;
uint32_t revision;
uint16_t version;
uint16_t unknown;
uint8_t *data;
};
struct group;
union subgroup_record{
int type;
struct group subgroup;
struct record record;
};
struct record_list{
union subgroup_record subgroup_record;
struct record_list *next;
};
struct group{
char type[4];
uint32_t group_size;
uint8_t label[4]; // depends on group_type
int32_t group_type;
uint16_t stamp;
uint16_t unknown1;
uint16_t version;
uint16_t unknown2;
struct record_list record_list;
};
struct group_list{
struct group group;
struct group_list *next;
};
struct plugin{
struct record header;
struct group_list top_groups;
};
The compiler gives me this error: 编译器给我这个错误:
error: field ‘subgroup’ has incomplete type
Forward declaring the struct didn't help, typedef'ing the struct and changing the declarations also didn't help and I'd rather not have pointers everywhere (for a beginner the allocating and freeing memory is a bit scary) 前面声明结构没有帮助,typedef结构和更改声明也没有帮助,我宁愿没有指针到处(对于初学者来说,分配和释放内存有点可怕)
Any solution for this? 对此有何解决方案?
Thanks! 谢谢!
You have a circular recursive definition. 你有一个循环的递归定义。
The type struct group
contains the type struct record_list
, which contains the type union subgroup_record
, which contains the type struct group
类型
struct group
包含struct record_list
类型,它包含union subgroup_record
类型,其中包含类型struct group
A type cannot contain itself. 类型不能包含自身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.