structure size and structure element offset calculation issue
Jonathan Wakely
jwakely.gcc@gmail.com
Fri May 23 10:41:00 GMT 2014
On 23 May 2014 11:06, 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 ?
To ensure that if you have an array of those objects the int member
will always be on a 4-byte boundary.
> why cross compiler trying to make structure size multiple of 4 ?
Because GCC thinks short has an alignment of 4 on your custom processor.
More information about the Gcc-help
mailing list