typedef union { unsigned x; } T;
T a;
a.x = 3;
int main() { return 0; }
Trying to compile this code, with gcc t.c, I get
error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
using
gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
When I move a.x = 3; inside main, it behaves as expected.
I wish to find the passage from
ISO/IEC 9899:TC3
where it is explained that it is forbidden to assign values to a union in global namespace.
EDIT: with structures it happens the same.
It is described in the 6.9p1 of C99 (syntax of a translation-unit). You cannot have a statement outside of a function.