我试图编译一个依赖于稀疏0.4.1的项目,但是尝试编译稀疏0.4.1时,我遇到了以下编译器错误:

included from parse.c:25:
./parse.h:63:22: error: member of anonymous struct redeclares 'label_statement'
                        struct statement *label_statement;
                                          ^
./parse.h:40:22: note: previous declaration is here
                        struct statement *label_statement;


这让我感到困惑,因为它们是两个不同结构的不同成员,那么为什么会抱怨呢?

代码如下:

struct statement {
    enum statement_type type;
    struct position pos;
    union {
            struct /* declaration */ {
                    struct symbol_list *declaration;
            };
            struct /* label_arg */ {
                    struct symbol *label;
                    struct statement *label_statement;
            };
            struct {
                    struct expression *expression;
                    struct expression *context;
            };
            struct /* return_statement */ {
                    struct expression *ret_value;
                    struct symbol *ret_target;
            };
            struct /* if_statement */ {
                    struct expression *if_conditional;
                    struct statement *if_true;
                    struct statement *if_false;
            };
            struct /* compound_struct */ {
                    struct statement_list *stmts;
                    struct symbol *ret;
                    struct symbol *inline_fn;
                    struct statement *args;
            };
            struct /* labeled_struct */ {
                    struct symbol *label_identifier;
                    struct statement *label_statement;
            };
.......

最佳答案

您在同一联合中两次声明了label_statement语句,第一次在第40行中声明,第二次在第63行中声明

     struct statement *label_statement;


尝试编辑第二个的名称。

关于c - 编译稀疏0.4.1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13483974/

10-16 22:25