Is it safe to use an enum in a bit field?

It’s allowed in all C++ compilers, that supports standard. C++03 standard 9.6/3 A bit-field shall have integral or enumeration type (3.9.1). It is implementation-defined whether a plain (neither explicitly signed nor unsigned) char, short, int or long bit-field is signed or unsigned. C++03 standard 9.6/4 If the value of an enu- merator is stored into … Read more

Practical Use of Zero-Length Bitfields

You use a zero-length bitfield as a hacky way to get your compiler to lay out a structure to match some external requirement, be it another compiler’s or architecture’s notion of the layout (cross-platform data structures, such as in a binary file format) or a bit-level standard’s requirements (network packets or instruction opcodes). A real-world … Read more

tech