This is the mail archive of the gcc@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: uint64_t alignof odditity on x86


Jan Engelhardt <jengelh@medozas.de> writes:

> I noticed that __alignof__(uint64_t) will return 8, while
> __alignof__(struct { uint64_t x; }) will give only 4. This
> run on a typical 32-bit x86 CPU (GCC config below).
>
> What I am wondering about is why GCC was coded to give different
> alignments here. If aligning a single uint64_t to a boundary of 8 for
> whatever reason there may be (performance?), not doing so when it is
> inside a struct appears to be a discrepancy.

This question would have been more appropriate for the mailing list
gcc-help@gcc.gnu.org rather than gcc@gcc.gnu.org.  Please take any
followups to gcc-help.  Thanks.

The x86 ABI specifies the aligment of fields within a struct.  gcc can
not change that alignment without breaking the ABI.  This does not
matter much when the only field has type uint64_t, but it matters for a
case like "struct { int f1; uint64_t f2; };".  For a variable of type
uint64_t, it's OK for gcc to increase the alignment, since it does not
affec the ABI (although the required alignment is only 4, any program
must work if all uint64_t variables happen to be aligned on an 8-byte
boundary).

Ian


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