Take this structure for example:
struct Packing
{
int x; // 4-byte align
int y; // 4-byte align
short int z; // 2-byte align
char m; // 1-byte align;
char _pad[1]; // explicit padding
};
The sizeof this structure is 12-bytes.
So should store this struct in addresses multiples of the struct size (12-bytes) or in multiples of sizeof(int) (the largest alignment requirement among the members of the struct)?
Since multiples of 12 are also multiples of 4 (sizeof(int)) I guess the struct will be correctly aligned in addresses multiples of 12, but I might waste space that wouldnt be wasted if it was 4-byte aligned.
EDIT: At address 0x00000012 the structure would be aligned and the its first member would also be aligned because 12 is a multiple of 4. What if stored it at address 0x00000004? In this case the first element of the struct would be aligned but what about the structure itself?
should store this function, store what? - Mu Qiao__padis a reversed identifier. - R. Martinho Fernandes