I have a situation with two structures that are combined as members of a larger structure. The first one is 44 bytes, and the second one is 1047. The second structure ends with a char. Excerpt:
typedef struct
{
... (total of 44 bytes, all members naturally aligned)
} StructA;
typedef struct
{
...lots of stuff totaling 1046 bytes
char flag;
} StructB;
typedef struct
{
StructA a;
StructB b;
} StructC;
Printing sizeof of StructA and StructB produces the expected sizes of 44 and 1047 respectively. Printing sizeof StructC produces 1092, which is 44 + 1047 + 1. It seems pretty clear to me that the compiler is padding the overall structure because of the single byte at the end of StructB. But it's at the end...there are no following members that require alignment. So why is it padding StructC? And why does it not pad StructB the same way?
This is built with Microsoft Visual Studio 2013; we're also cross-platform, but I don't yet know if GNU compiler on Linux treats this the same or not. If it doesn't, that will also be a concern.
Thank you, Doug
Follow up:
My question was marked as a duplicate but the referral doesn't answer the specific issue I'm trying to address, which is specifically why padding was added at the end of the structure in one circumstance, but not in the other.