Your analysis is correct, except that there is an additional 4 bytes padding before the char *d
member. This is so that the d
member is aligned on an 8-byte boundary.
The pahole
output for this structure on x86-64 is:
struct how_many_bytes {
long int s[4]; /* 0 32 */
char c; /* 32 1 */
char e; /* 33 1 */
/* XXX 2 bytes hole, try to pack */
int i[2]; /* 36 8 */
/* XXX 4 bytes hole, try to pack */
char * d; /* 48 8 */
/* size: 56, cachelines: 1 */
/* sum members: 50, holes: 2, sum holes: 6 */
/* last cacheline: 56 bytes */
}; /* definitions: 1 */
No matter how you rearrange the members of this structure, you won't be able to do better than 6 bytes in total of padding. The sum of the sizes of the members is 50 bytes, and the maximum alignment of the structure members is 8, so even if you arrange the members in the optimal order there will be 6 bytes of padding at the end of the structure to round its size up to the next biggest multiple of 8.