/** * A cool use of union and anonymous structures * @author gtowell * Created April 21, 2021 * **/ // requires compiling like gcc -fms-extensions anonstruct.c // all documentation I read says this works too. I does not for me. gcc -std=c11 anonstruct.c // to make VSC happy, "compilerPath": "/usr/local/bin/gcc -fms-extensions ", #include // A simple structure typedef struct { int x; int y; } aa; // the imple structure, included anonymously and not, // in the same memory(!) through the use of a union. typedef struct { union { aa; aa aaa; }; int z; } bb; int main(int argc, char const *argv[]) { bb b; b.aaa.x = 10; b.y = 40; b.z = 20; printf("%d %d %d\n", b.z, b.aaa.x, b.y); return 0; }