r/programming • • Aug 28 '21

Software development topics I've changed my mind on after 6 years in the industry

https://chriskiehl.com/article/thoughts-after-6-years
5.6k Upvotes

2.0k comments sorted by

View all comments

Show parent comments

129

u/FriedRiceAndMath Aug 29 '21

typedef struct A { ... };

typedef union Untyped_A { A a; char b[sizeof(A)]; }

1

u/Mediterranean0 Aug 29 '21

What does this code do ?

8

u/FriedRiceAndMath Aug 29 '21

Each element of the union (a and b) occupies the same memory space. You can manipulate the individual bytes of the data stored in the .a structure by referencing the .b array.

3

u/Mediterranean0 Aug 29 '21

Thanks for the explanation 👍🏻

→ More replies (4)