Suppose I have a POD type:
struct A { char a; int b; };
On my system, sizeof(A) == 8 , although sizeof(char) == 1 and sizeof(b) == 4 . This means that the data structure contains 3 unused bytes.
Now suppose that
A x = ...; A y =x;
Question:
Is it guaranteed that all 8 bytes x and y will be identical, even these 3 unused ones?
Equivalently, if I transfer the base bytes of some A objects to another program that does not understand their meaning or structure and treat them as an array of 8 bytes, can this other program safely compare two A for equality?
Note: In the experiment with gcc 7, it seems that these bytes are being copied. I would like to know if this is guaranteed.
c ++ copy-constructor
Szabolcs Oct 22 '17 at 14:10 2017-10-22 14:10
source share