C++ 2-bit bitfield arrays possible?
问题 I have a struct of 2-bit bitfields like this: struct MyStruct { unsigned __int32 info0 : 2; unsigned __int32 info1 : 2; unsigned __int32 info2 : 2; ... unsigned __int32 info59 : 2; }; And another like this going up to 120... Is there a way to write and address them as an array? 回答1: If you can't use Paul R's answer for whatever reason, you can always use a custom accessor with a standard array : static unsigned __int8 infos[30]; // 240 bits allocated unsigned __int8 getInfo( unsigned short id