This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: are statically allocated structs always aligned to a machine word on x86/x86_64?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: john smith <wempwer at gmail dot com>, gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Sun, 23 Aug 2015 14:52:48 +0100
- Subject: Re: are statically allocated structs always aligned to a machine word on x86/x86_64?
- Authentication-results: sourceware.org; auth=none
- References: <CAKmQUfZT04z8pd9bvqazEPkV1iqRrUxw82nxd3RbOerVbyxqhA at mail dot gmail dot com> <CAH6eHdQdAt1sqtnZe7CiJtWKb_SeggnXieiiR7Wf4D8Uf1sLyg at mail dot gmail dot com> <CAKmQUfbuZ-tbggq8iCxYd4G_VSnVgbS-jBzPc6AYxQhRtN65GQ at mail dot gmail dot com> <CAH6eHdQUBc_Rh_zcTD1hKvCV=XPt9KHupGgFcT2aks-fu=BS3g at mail dot gmail dot com> <20150823110539 dot GA16487 at gate dot crashing dot org> <CAH6eHdSA+8CdmC_0jQzcJcJLuy-6UtG365ObjLtU61DrR2iQBg at mail dot gmail dot com>
On 23 August 2015 at 14:49, Jonathan Wakely wrote:
> On 23 August 2015 at 12:05, Segher Boessenkool wrote:
>> On Sun, Aug 23, 2015 at 12:15:56AM +0100, Jonathan Wakely wrote:
>>> because alignments must be a power of 2.
>>
>> That is true in C++, but not true in C or even POSIX afaics?
>
> C11 Â6.2.8
>
> "Every valid alignment value shall be a nonnegative integral power of two."
Anyway, the point is that John's assumption is wrong, you can have
alignments larger than one and smaller than sizeof(int) in which case
objects with those alignments don't have to be word-aligned.
If you want to know whether an object will be word-aligned then use
the alignof keyword, rather than incorrect assumptions.