There are 3 bytes of padding after s1::c
, same as after s2::c1
, in the i386 System V ABI's struct layout rules. (And most normal ABIs.)
The total struct size has to be a multiple of its alignof()
for arrays to work: structs in contiguous memory, each one taking sizeof(struct s1)
, but also the start of each struct being aligned so that the int
members are aligned.
Look at the sizeof()
and alignof()
of both types, and of int vs. char. sizeof(char) = 1 as defined by ISO C, and in i386 SysV, sizeof(int) = alignof(int) = 4.
If you had a struct { char foo[8]; char c; };
then it's total size would only be 9 bytes, because alignof(char) = 1.