[LCP]struct size

Keith Schincke kschin at unf.edu
Sun Aug 19 05:28:55 UTC 2001


I think the answer is: Word alignment. The ammount of alignment depends on
the platforam I think. The details are pretty interesting if you can find them.

On Sat, 18 Aug 2001, Srinath Thiruvengadam wrote:

> 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
>

-- 
Keith Schincke           My dawg is always with me.
Jacksonville, Fl               00 Spool - Wild at Heart
http://www.unf.edu/~kschin                           Email: kschin at unf.edu
++The opinions in my email are mine only and are not those of my employer++

  |  |   |   |  |
-( -(  -O_O-  )- )- Vibrating Cunning Pike






More information about the linuxCprogramming mailing list