Consider:
struct mystruct_A
{
char a;
int b;
char c;
} x;
struct mystruct_B
{
int b;
char a;
} y;
The sizes of the structur
Padding and packing are just two aspects of the same thing:
In mystruct_A
, assuming a default alignment of 4, each member is aligned on a multiple of 4 bytes. Since the size of char
is 1, the padding for a
and c
is 4 - 1 = 3 bytes while no padding is required for int b
which is already 4 bytes. It works the same way for mystruct_B
.