hier ist sehr Code Problem vereinfacht die ich habe:Anonyme Union in Struct nicht in 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; }
Und was ich undestand nicht wissen, ist dies:
$ 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’
Mit GCC
ohne -std
Option Code oben ohne Probleme kompiliert (und die ähnlicher Code funktioniert ziemlich gut), aber es scheint, dass c99
diese Technik nicht erlaubt. Warum ist es so und ist es möglich, c99
(oder c89
, c90
) kompatibel zu machen? Vielen Dank.
Nur eine Anmerkung, clang kompiliert gegebenen Code mit und ohne '-std = c99' still, ohne irgendwelche Fehler und Warnungen. – Martin