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.