This question is related to How to ensure a member is 4-byte aligned?
Example:
struct Aligned
{
char c;
__attribute__((__aligned__(4))) int32_t member;
}
struct Test
{
char c;
Aligned s;//is s.member 4 bytes aligned?
}
void f1()
{
char c1;
Aligned s;//is s.member 4 bytes aligned?
char c2;
}
void f2()
{
Aligned* s = new Aligned();//is s.member 4 bytes aligned?
}
Can you please explain if "member" is 4 bytes aligned in all cases, and if yes how this works?
Edit: I forgot the case where Aligned is derived from other struct:
struct Aligned : public SomeVariableSizeStruct
{
char c;
__attribute__((__aligned__(4))) int32_t member;
}
Second Edit: My questions is: is always first member of a structure 4 bytes aligned? Because in all cases presented here the first variable address might not be 4 bytes aligned and the 3 bytes padding doesn't guarantee that "member" is 4 bytes aligned