[LCP]struct size

Andrew Weaver Andrew.Weaver at tecnomen.fi
Mon Aug 20 17:54:47 UTC 2001


Padding for alignment. See __attribute__((packed)) 

> -----Original Message-----
> From:	Srinath Thiruvengadam [SMTP:redindian at zxmail.com]
> Sent:	Saturday, August 18, 2001 2:58 AM
> To:	linuxCprogramming at lists.linux.org.au
> Subject:	[LCP]struct size
> Importance:	High
> 
> hello all,
>  
> please see this code
>  
> struct somestruct
> {
>  int a;
>  char b;
>  char c;
> }stvar;
>  
> int main()
> {
>   printf("%d",sizeof(stvar));
> }
>  
> the o/p is 8.  i was expecting 6 as 'a' occupies 4 bytest and 'b','c' 
> one byte each !  how is it 8 ??
>  
> Thanks, 
> Srinath



More information about the linuxCprogramming mailing list