==> "Ho-Fa Chiang" <
ho...@ms1.hinet.net>, 信區: oop
在 oop 版提到:
: 請各位高手幫在下解決sizeof()的問題
: 當我用 VC4.2B 的 sizeof()去算下面的結構時為,
: typedef struct{
: char tt[16];
: long size;
: char objects;
: }OFFSET1;
: typedef struct{
: char type;
: long offset;
: long size;
: }OFFSET2;
: sizeof(OFFSET1) ---> 24
: sizeof(OFFSET2) ---> 12
: 但如只計算每一個變數因該為
: char tt[16] ---16 char type ----1
: long size ----4 long offset --4
: long object --1 long size ---4
: -============ ===============
: 合計: 21 9
: 我用Turbo C 算沒錯,或許是 VC 本身的問題但我要如何解決
: 請幫幫我,謝謝
:
Email:ho...@ms1.hinet.net When applied to a structure type or variable, sizeof returns the actual size,
which may include padding bytes inserted for alignment.