看板 C_and_CPP 關於我們 聯絡資訊
程式碼: http://paste.plurk.com/show/346938 問題: 有高手能夠教一下這個 sizeof 的結果是怎麼算的嗎? 我從一開始的 class x { public: float x; short b; int c; } 答案就算不對了,明明是 4 + 2 + 4 可是 print 出來的卻是 12 更不用說後面的繼承問題了 這真的是想破頭也不知道是哪裡關念不對 煩請高手解惑一下 Orz -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.37.83.161
dendrobium:google "Data structure alignment" 01/04 02:44
linhomeyeu:http://bit.ly/f9NydJ 01/04 11:08
wawi:compiler會幫你的short補成4 bytes 01/04 12:25
clarkman:offsetof去算 01/04 12:41