This is the mail archive of the gcc-help@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: about alignment of structure


2010/5/19 Ian Lance Taylor <iant@google.com>:
> YC Wang <wangyc0307@gmail.com> writes:
>
>> When gcc processes a strucure declaration, what rules it will use? As
>> far as I know, gcc is supposed to conform to the platform ABI. For
>> example, below is extracted from the SysV i386 ABI:
>>
>> Â- An entire structure or union object is aligned on the same boundary as
>> Âits most strictly aligned member.
>>
>> Â- Each member is assigned to the lowest available offset with the
>> Âappropriate alignment. This may require internal padding, depending on the
>> Âprevious member.
>>
>> Â- A structure's size is increased, if necessary, to make it a multiple
>> Âof the alignment. This may require tail padding, depending on the last
>> Âmember.
>>
>> So, should gcc (whatever versions) Âalways comform to these rules
>> (assume we don't Âspecify special attributes or options)?
>
> All versions of gcc that use the 386 ELF ABI will follow those rules.
>
>> I ask this
>> question because I just read the paper "stable_api_nonsense" by Greg
>> KH from Linux kernel Documentation, and begin with line 54 the paper
>> says "Depending on the version of the C compiler you use, different
>> kernel data structures will contain different alignment of
>> structures".
>
> You will different alignment on different processors, but I'm not
> aware of any case where you will different alignment for the same
> processor from different versions of gcc. ÂOf course there can be
> bugs, but bugs in this area are rare.
>
> Ian
>

Thanks for the reply. So may I make the conclusion that on a givin
processor, any version of gcc, if no bugs, is supposed to generate the
same alignment?

YC Wang


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