[LCP]struct size

Roberto Diaz rdiazmartin at vivaldi.dhis.org
Sun Aug 19 05:56:27 UTC 2001


> please see this code
> struct somestruct
> {
>  int a;
>  char b;
>  char c;
> }stvar;
> int main()
> {
>   printf("%d",sizeof stvar); /* you dont need () since it is an instance*/
> }
> the o/p is 8.  i was expecting 6 as 'a' occupies 4 bytest and 'b','c' 
> one byte each !  how is it 8 ??

Aligment.. the word size in i386 is 32 bits 4 bytes so the compiler left
holes into your structure so all is aligned at 4 bytes boundaries.


Regards

Roberto

------------------------------------------------------------------------
Roberto Diaz <rdiazmartin at vivaldi.dhis.org>
http://vivaldi.dhis.org
Powered by GNU running on a Linux kernel.
Powered by Debian (The real wonder)

Concerto Grosso Op. 3/8 A minor
Antonio Vivaldi (so... do you need beautiful words?)
------------------------------------------------------------------------




More information about the linuxCprogramming mailing list