这里很简单的问题,我的代码有:结构中的匿名联合不在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’ has no member named ‘int_n’
使用GCC
没有-std
选项编译代码上面没有任何问题(和类似的代码工作得很好),但似乎c99
不允许这种技术。为什么它是如此,是否有可能使c99
(或c89
,c90
)兼容?谢谢。
只是一个说明,铿锵编写代码带和不带'-std = c99'静默,没有任何错误和警告。 – Martin 2010-07-12 11:58:21