Memory position of elements in C/C++ union
I have a union in C like this: union AUnion { struct CharBuf { char *buf; size_t len; } charbuf; uint8_t num; double fp_num; }; My question is, can I guarantee that if given the following: union AUnion u; Then the following are true: &u == &u.num &u == &u.fp_num &u == &u.charbuf I.e they all start at the beginning of the memory segment where u is stored. In the case of this C program compiled with gcc version 5.3.0 and -std=c11 the above is true: #include <stdio.h> #include <stdint.h> #include <stdlib.h> union AUnion { struct CharBuf { char *buf; size_t len; } charbuf; uint8_t num; double fp