可能重复:
Why isn’t sizeof for a struct equal to the sum of sizeof of each member?C++结构尺寸:2 + 4 + 2 + 2 + 4 = 16
为什么这种结构的16个字节的sizeof();
?我正在编译g ++。
struct bitmapfileheader {
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
};
Dupe:http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member – 2009-12-09 20:29:41
http:///en.wikipedia.org/wiki/Sizeof#Structure_padding – 2009-12-09 20:29:56
谁说short是2而int是4? – 2009-12-09 20:35:53