这是我遇到的问题的非常简化的代码:
枚举节点类型{t_int,t_double};
结构体“int_node”{ int value; };
结构体“double_node”{ double value; };
结构体“node”{ enum node_type type; 联合{ struct int_node int_n; struct double_node double_n; }; };
主函数{ 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’ has no member named ‘int_n’
在没有任何问题的情况下编译上面的代码(类似的代码运行良好),但是似乎c99不允许这种技术。为什么会这样?是否可能使其与c99(c89、c90)兼容?谢谢。
枚举节点类型{t_int,t_double};
结构体“int_node”{ int value; };
结构体“double_node”{ double value; };
结构体“node”{ enum node_type type; 联合{ struct int_node int_n; struct double_node double_n; }; };
主函数{ 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’ has no member named ‘int_n’
在没有任何问题的情况下编译上面的代码(类似的代码运行良好),但是似乎c99不允许这种技术。为什么会这样?是否可能使其与c99(c89、c90)兼容?谢谢。