Anonymous unions
An 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 directlycval = 'c'; // assigns a new value to the unnamed, anonymous union objectival = 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.
Note
An anonymous union cannot have private ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access