> -----Ursprüngliche Nachricht----- > Von: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx]Im > Auftrag von Xiaoshan Sun > Gesendet: Dienstag, 19. April 2005 04:48 > An: gcc-help@xxxxxxxxxxx > Betreff: "sizeof" get unwanted result > > > hi, > i use "sizeof" to get the size of a struct ,defined as: > typedef struct _A { > long data1; > unsigned short data2; > long data3; > }A; > i guess the sizeof(A) should be 10 .however when i compile > and print the > value of "sizeof(A)" ,the reult is 12!! > so where's the extra 2 bytes? how can i get the gcc to calculate the > desired size ?? > an aligned issue?? On a 32bit machine the compiler align each element on a 32bit even address. So between data2 and data3 there be 2 Byte filldata. On a 64bit machine the compiler align addresses to 64bit so he fill with 6 Bytes. To avoid use the packed attribute as proposed by Kevin. regards Martin