In a previous question, I learned that when a structure that has 8-byte alignment gets embedded into another structure with 4-byte alignment, a padding is needed before the 8-byte aligned structure.
Understood.
At least I thought that I understood.
The VS 2012 docs say:
For structures, unions, and arrays, the alignment-requirement is the largest alignment-requirement of its members.
So, if I have a structure like this:
typedef struct s_inner {
unsigned long ul1;
double dbl1;
fourth_struct s4;
unsigned long ul2;
int i1;
} t_inner;
I'd expect all members of this structure would be 8-byte aligned since the double is 8-byte aligned.
But my memory dump shows me this:

t_inner starts from address 1B8:
1B8: theunsigned longis padded because the structure is 8-byte aligned1C0: Thedoubleconsumes 8 bytes1C8:fourth_structfollows, it has 4-byte alignment
Until now, everything is as expected. But now the alignment switches inside t_inner:
On address 1E8, I'd expect to find just the unsigned long here, padded with 4 bytes so that the following int is also aligned on 8 bytes. But it seems as if the alignment has now changed since the unsigned long does not carry padding bytes. Instead, the following int is placed with a 4-byte alignment.
Why does the alignment switch inside t_inner? Which rule is applied here?
structor it may not, depending on the alignment requirements of all the outerstruct's members up to and including the innerstruct. The alignment requirement of the outerstructdoesn't directly factor in, nor does the fact that the outer and innerstructs have different alignment requirements. - John Bollinger