Just ran into a similar problem. It seems that gcc just doesn't like bit fields that intersect the type width (like two in the example)?
If you change all types to uint16_t , gcc will accept:
union pack_it_in { struct { uint16_t zero : 3; uint16_t one : 2; uint16_t two : 6; uint16_t three : 4; uint16_t four : 1; } __attribute__((packed)) u8_2; uint16_t u16; };
A layout is what you need, even if the types of these elements do not match.
source share