I've written a header file (bitfield.h) that provides structures of bit fields as a template/macro library:


It is more portable and flexible, and has comparable performance to the bit field feature of the base language. At least, the code optimization looks good using gcc, I'm not able to check with VC++. For example, to xor 33 into a bitfield:

BITF(My_descriptor, my_target, sub_struct.some_field) ^= 33;

It's possible to directly access bit fields in device registers, including device registers accessed using inp/outp. This works even when device registers are accessed indirectly, via a register address and read/write buffer combo.