Anonymous structures and anonymous unions
Anonymous structures and anonymous unions are type definitions without names, and they are usually used in other types as a nested type. It is easier to explain them with an example. Here, you can see a type that has both an anonymous structure and an anonymous union in one place, displayed in Code Box 12-10:
typedef struct { union { struct { int x; int y; }; int data[2]; }; } point_t;
Code Box 12-10: Example of an anonymous structure together with an anonymous union
The preceding type uses the same memory for the anonymous structure and the byte array field data
. The following code box shows how it can be used in a real example:
#include <stdio.h> typedef struct { union { struct { int x; int y; }; int data[2]; }; } point_t; int main(int argc, char** argv) { point_t p; p.x = 10; p.data[1] = -5; printf("Point (%d, %d) using an anonymous structure inside an...