struct foo {
char a;
int b;
char c;
int d;
};
but this: struct foo {
int b; // or int b, c;
int c;
char a;
char c;
};
Basically if you sort the types by size in reverse descending order, you get optimal packing without messing with compiler-specific packing extensions that skew alignment and possibly bloat code.The worst that you will get is padding at the end of the structure so that if two or more of them are arrayed, the first member is correctly aligned at all the array indices.