public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Where does C standard mention alignment requirements as written in gcc manual?
@ 2015-08-18 15:04 john smith
  2015-08-18 15:50 ` Segher Boessenkool
  0 siblings, 1 reply; 5+ messages in thread
From: john smith @ 2015-08-18 15:04 UTC (permalink / raw)
  To: gcc-help

In gcc manual it says:

"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.

-- 
<wempwer@gmail.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Where does C standard mention alignment requirements as written in gcc manual?
  2015-08-18 15:04 Where does C standard mention alignment requirements as written in gcc manual? john smith
@ 2015-08-18 15:50 ` Segher Boessenkool
  2015-08-18 15:57   ` john smith
  0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2015-08-18 15:50 UTC (permalink / raw)
  To: john smith; +Cc: gcc-help

On Tue, Aug 18, 2015 at 05:04:28PM +0200, john smith wrote:
> In gcc manual it says:
> 
> "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 ?


Segher

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Where does C standard mention alignment requirements as written in gcc manual?
  2015-08-18 15:50 ` Segher Boessenkool
@ 2015-08-18 15:57   ` john smith
  2015-08-18 16:25     ` Nicholas Mc Guire
  2015-08-18 16:28     ` Segher Boessenkool
  0 siblings, 2 replies; 5+ messages in thread
From: john smith @ 2015-08-18 15:57 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-help

 On Tue, Aug 18, 2015 at 5:50 PM, Segher Boessenkool
<segher@kernel.crashing.org> wrote:
> On Tue, Aug 18, 2015 at 05:04:28PM +0200, john smith wrote:
>> In gcc manual it says:
>>
>> "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".

-- 
<wempwer@gmail.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Where does C standard mention alignment requirements as written in gcc manual?
  2015-08-18 15:57   ` john smith
@ 2015-08-18 16:25     ` Nicholas Mc Guire
  2015-08-18 16:28     ` Segher Boessenkool
  1 sibling, 0 replies; 5+ messages in thread
From: Nicholas Mc Guire @ 2015-08-18 16:25 UTC (permalink / raw)
  To: john smith; +Cc: Segher Boessenkool, gcc-help

On Tue, 18 Aug 2015, john smith wrote:

>  On Tue, Aug 18, 2015 at 5:50 PM, Segher Boessenkool
> <segher@kernel.crashing.org> wrote:
> > On Tue, Aug 18, 2015 at 05:04:28PM +0200, john smith wrote:
> >> In gcc manual it says:
> >>
> >> "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".
>
I guess 6.2.5 subclause 25 together with note 39 (interchangeablity) 
would result in "perfect multiple of the lowest common multiple" 

see also 6.2.5 subclause 20 on derived types.

thx!
hofrat

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Where does C standard mention alignment requirements as written in gcc manual?
  2015-08-18 15:57   ` john smith
  2015-08-18 16:25     ` Nicholas Mc Guire
@ 2015-08-18 16:28     ` Segher Boessenkool
  1 sibling, 0 replies; 5+ messages in thread
From: Segher Boessenkool @ 2015-08-18 16:28 UTC (permalink / raw)
  To: john smith; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-18 16:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-18 15:04 Where does C standard mention alignment requirements as written in gcc manual? john smith
2015-08-18 15:50 ` Segher Boessenkool
2015-08-18 15:57   ` john smith
2015-08-18 16:25     ` Nicholas Mc Guire
2015-08-18 16:28     ` Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).