看板 C_and_CPP 關於我們 聯絡資訊
小紅帽 64 bit gcc 3.4 struct A { struct B { struct C { int a ; double a ; float a ; int b ; double b ; float b ; int c ; float c ; float c ; } ; } ; } ; sizeof : 12 24 12 想不透為什麼 struct B 會是 24 阿~~~ 不是應該 8 + 8 + 4 = 20 嗎 O_Q??? -- To iterate is human, to recurse, divine. 遞迴只應天上有, 凡人該當用迴圈.   L. Peter Deutsch -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.109.211
legnaleurc:因為double是8byte的block吧,float就被padding了 05/14 01:54
Chevelle:long double? 05/14 03:54
yoco315:這個我困惑了.. double 8byte 沒必要去 padding float 阿 05/14 04:39
chrisdar:padding 會補到最大內建型別大小的整數倍 05/14 09:00
chrisdar: ^結構內用到的 05/14 09:01
VictorTom:小弟我記得應該padding到自己這個member的倍數address就 05/14 09:04
VictorTom:好了啊@_@" 跟y大有同樣的疑惑....Orz 05/14 09:04
VictorTom:雄雄想到, 這樣也做padding, 不會是為了開array時還是都 05/14 09:17
VictorTom:有alignment吧?? 05/14 09:17
VictorTom: 該不會 05/14 09:18
VictorTom:所以自然就形成了c大所說的結果這樣@_@" 05/14 09:19
chrisdar: 我也是這麼認為的 05/14 09:19
yoco315:ㄟ~~~!有道理耶!XD 05/14 19:01