union
sAn anonymous union
is an unnamed union
that does not include any declarations between the close curly that ends its body and the semicolon that ends the union
definition (§ 2.6.1, p. 73). When we define an anonymous union
the compiler automatically creates an unnamed object of the newly defined union
type:
union { // anonymous union
char cval;
int ival;
double dval;
}; // defines an unnamed object, whose members we can access directly
cval = 'c'; // assigns a new value to the unnamed, anonymous union object
ival = 42; // that object now holds the value 42
The members of an anonymous union
are directly accessible in the scope where the anonymous union
is defined.