Sayeth the C standard, regarding anonymous structs and unions:
6.7.2.1 p13. An unnamed member whose type specifier is a structure specifier with no tag is called an anonymous structure; an unnamed member whose type specifier is a union specifier with no tag is called an anonymous union. The members of an anonymous structure or union are considered to be members of the containing structure or union. This applies recursively if the containing structure or union is also anonymous.
Note emphasis: rather than the members of the anonymous struct/union being in the scope of the containing struct/union, they are fully members of it. But there are responsibilities attached to that:
6.7.2.1 p16. The size of a union is sufficient to contain the largest of its members. The value of at most one of the members can be stored in a union object at any time. A pointer to a union object, suitably converted, points to each of its members (or if a member is a bit-field, then to the unit in which it resides), and vice versa.
Taken together, those seem to imply that the members of an anonymous struct within a (named) union behave like co-located, mutually-exclusive members of the union. So the following should work:
union Foo
{
struct
{
char a;
char b;
};
};
int main(void) {
union Foo f;
assert(&f == &(f.a) && &f == &(f.b));
}
Of course, it doesn't, and we wouldn't want it to... there'd be no reason for anonymous structs/unions if they worked like the above. Still, the Standard seems unambiguous on that point. Is there something I'm missing?