C结构,不完整的字段类型

时间:2016-09-10 02:59:34

标签: c struct

我的结构声明的片段:

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;
};

编译器给出了这个错误:

error: field ‘subgroup’ has incomplete type

前面声明结构没有帮助,键入结构和更改声明也没有帮助,我宁愿没有指针到处(对于初学者来说,分配和释放记忆有点可怕)

对此有何解决方案?

谢谢!

1 个答案:

答案 0 :(得分:2)

您有一个循环递归定义。

类型struct group包含struct record_list类型,其中包含union subgroup_record类型,其中包含类型struct group

类型不能包含自身。