This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Where does C standard mention alignment requirements as written in gcc manual?
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: john smith <wempwer at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 18 Aug 2015 11:28:35 -0500
- Subject: Re: Where does C standard mention alignment requirements as written in gcc manual?
- Authentication-results: sourceware.org; auth=none
- References: <CAKmQUfai7NdLwiQRQ-0Nd4biPjyBgMp46K3WhO7xOn=Oi4zLLw at mail dot gmail dot com> <20150818155042 dot GC30482 at gate dot crashing dot org> <CAKmQUfYdG9b45tpxh86z-JTTgKt=d7FEknb7HE_jMvjQg3W+nQ at mail dot gmail dot com>
On Tue, Aug 18, 2015 at 05:57:36PM +0200, john smith wrote:
> >> "Note that the alignment of any given struct or union type is required
> >> by the ISO C standard to be at least a perfect multiple of the lowest
> >> common multiple of the alignments of all of the members of the struct
> >> or union in question."
> >>
> >> Where exactly is this requirement mentioned in C standard? I was
> >> looking for it in both C99 and C11 drafts and couldn't find it.
> >
> > C99 6.7.2.1/12 ?
>
> It just says that "Each non-bit-field member of a structure or union
> object is aligned in an implementation-defined manner appropriate to
> its type.". It doesn't require an overall alignment of the structure
> to be "at least a perfect multiple of the lowest common multiple of
> the alignments of all of the members of the struct".
If the alignment of any member of the struct is A, the alignment of the
struct has to be a multiple of A (by the above, and the definition of
alignment). Now consider all members together, and you get what the
GCC manual says.
Segher