開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
問題(Question):
想要宣告一個4bits的正整數,
存放範圍 0~15
不曉得這樣的宣告方式正不正確?
struct {
unsigned int boy : 4;
unsigned int girl : 4;
} age;
不曉得這樣是不是
boy 4 bits
girl 4 bits
我看網路資料他的參考Example是
struct {
unsigned int widthValidated : 1;
unsigned int heightValidated : 1;
} status;
The above structure requires 4 bytes of memory space for status variable, but
only 2 bits will be used to store the values.
宣告4 bytes 但是只有2 bits會存放到memory
感謝大大幫忙!