struct unaming
{
char f;
double dd;
struct
{
int data;
char c;
double d;
};
};
I was expecting the size of this structure to be 40 bytes. But compiler returned 32 bytes. I was expecting the following layout.
[char f][7 bytes][double dd] [int data][4 bytes][char c][7bytes][double d] = 40
This was based on the rule that structures and its member variables will be aligned to the greatest size data type present.
But looks like Compiler re-ordered the unamed structured. Is that the case? Why 32 Bytes?
[char f][7 bytes][double dd][int data][char c][3 bytes][double d] = 32. The compiler doesn't align each member to the largest alignment for a given data type. Each type has an alignment, and must be aligned to that. For primitive types like these, AFAIK, their alignments are their sizes - Justinalignof. - tadmanoffsetof, too - Remy Lebeau