Re: structure size and structure element offset calculation issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/23/2014 11:06 AM, Sivaprasad wrote:
> I have a confusion about structure size calculation.
> 
> I have tried to compared  structure size result with
> gcc version 4.7.2 20121109 (Red Hat 4.7.2-8)  generates code for x86 machine
> and
> cross compiler with gcc version 4.3.4  generate code for custom processor.
> 
> struct sample
> {
>    short int s;
> }a;
> 
> sizeof(a) showing 2 bytes with x86 gcc and 4 bytes with cross compiler.
> 
> struct sample
> {
>    int i;
>    short int s;
> }a;
> 
> sizeof(a) showing 8 bytes with x86 gcc and 8 bytes with cross compiler.
> 
> When compiler will add hole at end of the structure ?
> why cross compiler trying to make structure size multiple of 4 ?

Because the structure is aligned according to the alignment of its largest
member.  In this case the largest alignment is 4.  You can use the
packed attribute to change this.

Andrew.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux