I have this warning pop up when I'm trying to compile the following union:
10:5: note: offset of packed bit-field 'main()::pack_it_in::<anonymous struct>::two' has changed in GCC 4.4
#pragma GCC diagnostic ignore "-Wpacked-bitfield-compat"
union pack_it_in {
struct
{
uint8_t zero : 3;
uint8_t one : 2;
uint8_t two : 6;
uint8_t three : 4;
uint8_t four : 1;
} __attribute__((packed)) u8_2;
uint16_t u16;
};
#pragma GCC diagnostic pop
#pragma does not ignore that note. Is there a way to make #pragma work without having to use -Wno-packed-bitfield-compat
since I want this warning ignored only for two of my eight unions?
Just ran into a similar issue. It seems that gcc just doesn't like bitfields that cross the width of the type (as
two
does in the example)?If you change all the types to
uint16_t
, gcc accepts:The layout is what you want it to be, even if the types of these members may not be.