__attribute__ aligned could be more efficient
Jonathan Wakely
jwakely.gcc@gmail.com
Sun Mar 29 21:40:00 GMT 2015
On 29 March 2015 at 20:28, Mason wrote:
> It seems to me that there is another possible layout for bar2:
>
> s(80) + int(4) + pad(44) = 128 bytes
>
> The problem then would be that struct foo2 pointers might either
> point to a "stand-alone" foo2 -- s(80) + pad(48) -- or to a bar2
> "inner struct" (one with the int before the padding).
And that's what kills your idea.
Given a pointer to foo2 I should be able to do a memcpy(p,
sizeof(struct foo2), q) and not worry about overwriting some other
value that is not part of the foo2 object.
> If gcc generates code that leaves the padding untouched, then
> the same code works with both variants, and my suggestion would
> be valid. Or did I get something wrong?
As Andreas already said, structure members cannot overlap.
More information about the Gcc-help
mailing list