On Sun, May 01, 2005 at 11:25:53PM +0300, Dmitry Nezhevenko wrote: > Вопрос немного не в тему рассылки но тем не менее. > Есть простенькая прога на C: > ============== > #include <stdio.h> > int main(void) > { > struct oneRec > { > char b1; > char b2; > short id; > char lang; > char b3[2]; > char b4[2]; > > }; > > printf("sizeof(char)=%d\n",sizeof(char)); > printf("sizeof(short)=%d\n",sizeof(short)); > printf("sizeof(struct oneRec)=%d\n",sizeof(struct oneRec)); > } > > ============== > У меня она выдает: > sizeof(char)=1 > sizeof(short)=2 > sizeof(struct oneRec)=10 > > А теперь считаем b1, b2 - по байту, id - 2 байта, lang - 1 байт, b3 = 2 > байта, > b4 = 2 байта. В сумме 9 байт. Но почему sizeof(struct oneRec)=10? > > gcc version 3.3.5 (Debian 1:3.3.5-8) [EMAIL PROTECTED]:/tmp$ cat 1.c #include <stdio.h> int main(void) { struct oneRec { char b1; char b2; short id; char lang; char b3[2]; char b4[2]; } __attribute__((packed));
printf("sizeof(char)=%d\n",sizeof(char)); printf("sizeof(short)=%d\n",sizeof(short)); printf("sizeof(struct oneRec)=%d\n",sizeof(struct oneRec)); } [EMAIL PROTECTED]:/tmp$ gcc 1.c [EMAIL PROTECTED]:/tmp$ ./a.out sizeof(char)=1 sizeof(short)=2 sizeof(struct oneRec)=9 Дальше рассказывать? -- Best regards, Evgeny Khoruzhy [EMAIL PROTECTED] A: No Q: Should I quote below my post? -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]