This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __attribute__ aligned could be more efficient


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]