相关疑难解决方法(0)

struct中的匿名联合不在c99中?

这里是我所遇到的非常简化的问题代码:

enum node_type {
    t_int, t_double
};

struct int_node {
    int value;
};

struct double_node {
    double value;
};

struct node {
    enum node_type type;
    union {
        struct int_node int_n;
        struct double_node double_n;
    };
};

int main(void) {
    struct int_node i;
    i.value = 10;
    struct node n;
    n.type = t_int;
    n.int_n = i;
    return 0;
}

我不明白的是:

$ cc us.c 
$ cc -std=c99 us.c 
us.c:18:4: warning: declaration does not declare anything
us.c: In function ‘main’:
us.c:26:4: error: ‘struct node’ …

c gcc struct c99 unions

49
推荐指数
5
解决办法
3万
查看次数

标签 统计

c ×1

c99 ×1

gcc ×1

struct ×1

unions ×1