Tehn said:
Does anyone know of an equivalent macro to offset() that would work
for bit fields?
eg,
struct abc
{
enable: 1;
disable: 1;
speed: 6;
};
All these struct-declaration entries are missing a type-qualifier,
e.g. 'unsigned int'.
enable_bit_position = offset_bit(struct abc, enable);
No, there is none. Given an 'x' of type 'struct abc' it's just
referred by e.g. 'x.enable'. If you somehow legally access an
'unsigned int' at the start of your struct (a union might do that),
there is still 6.7.2.1p10, which makes it implementation-defined:
| An implementation may allocate any addressable storage unit large
| enough to hold a bitfield. If enough space remains, a bit-field
| that immediately follows another bit-field in a structure shall be
| packed into adjacent bits of the same unit. If insufficient space
| remains, whether a bit-field that does not fit is put into the next
| unit or overlaps adjacent units is implementation-defined. The
| order of allocation of bit-fields within a unit (high-order to
| low-order or low-order to high-order) is implementation-defined.
| The alignment of the addressable storage unit is unspecified.
Ralf