|
|
Le 17/02/2011 19:29, Darren New nous fit lire :
>
> Under what circumstances does it matter what order the members of a
> union are written in? When does it make a difference as to which type
> inside the union is declared first?
>
IBM extension: When you use zero-extent member in a union, it must be
the last "field".
e.g.
union Foo {
int a;
char b[0];
}
This syntax is supported by gcc too, but it does not care about the
order unless you want to initialise it. (for C99 and after)
typedef union {
int a;
long c;
char b[0];
} Foo;
main()
{
Foo k={257};
printf("Hello %d %d\n",k.b[0],k.b[1]);
}
So, the first might not be always important (it is for initialisation at
declaration time), but the last would, on AIX at least.
Post a reply to this message
|
|