看板 C_and_CPP 關於我們 聯絡資訊
不好意思請問一下...我在網路上範例都是直接說出 struct 大小為 4 byte struct { unsigned int widthValidated : 1; unsigned int heightValidated : 1; } status; 請問有比較詳細的算法嗎? 我的想法是 總共兩個 bit ,但一次存取是 4 byte ,所以後面 padding 30 bit 求出大小為 4 byte 不知道我這樣想對不對.... 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 58.115.110.72 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1463672022.A.2F5.html
Caesar08: 因為C++規定,sizeof不能是0 05/19 23:48
Caesar08: 既然不能是0,那最少也得是1 05/19 23:49
Caesar08: 阿,對不起,我看錯題目了... 05/19 23:55
bibo9901: 我以為這意思是: 只使用unsigned int 的 2 個bit ? 05/19 23:55
dijkstra: 同上 05/20 01:03
gn00618777: = = 那既然只用了 2 個 bit ,她怎出現 4 byte 呢? 05/20 05:32
gn00618777: http://goo.gl/IgVVpP 05/20 05:54
gn00618777: 那這樣我的想法應該是對的! 05/20 05:55
Caesar08: 另外,我不是很懂為什麼需要知道bit field的大小 05/20 10:37
Caesar08: bit field的實際大小是implementation-defined 05/20 10:42
james1022jk: 他應該是想要知道bit field怎麼影響struct的大小 05/20 11:19
gn00618777: 是的,我是想知道大小。http://goo.gl/zl5D7q 它的第 05/20 18:33
gn00618777: 一句有解答到我的問題,那這樣一切都瞭了~! 05/20 18:33
bibo9901: 所謂 implementation-defined 就是不同編譯器可能有不同 05/21 00:43
bibo9901: 作法 05/21 00:43
Caesar08: 他好像不是很懂甚麼是implementation-defined... 05/21 09:58