This is the mail archive of the
mailing list for the GCC project.
Re: __attribute__ aligned could be more efficient
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Mason <slash dot tmp at free dot fr>
- Cc: Jedrzej Dudkiewicz <jedrzej dot dudkiewicz at gmail dot com>, GCC help <gcc-help at gcc dot gnu dot org>
- Date: Sun, 29 Mar 2015 22:39:55 +0100
- Subject: Re: __attribute__ aligned could be more efficient
- Authentication-results: sourceware.org; auth=none
- References: <55182ED0 dot 4020602 at free dot fr> <CABJqhQOCD3hPuEhsGMZCofV3tQYEgDXBZWFhQtuf_v8M5gwWJg at mail dot gmail dot com> <55185249 dot 1080809 at free dot fr>
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.