I have the following style of union - defined in an interface so not easy to change.
I want to check if foo is the only field being set. And don't want to this by itemizing all the other fields.
So my immediate thoughts were to construct a mask, but then the bitfield is doing it's best to hide details like the position of a named field.
I couldn't think of anything better than creating a variable with the one field set and then inverting the raw field. Is there a neater solution?
typedef union struct {
unsigned char user:1;
unsigned char zero:1;
unsigned char foo:1;
unsigned char bar:1;
unsigned char blah:1;
unsigned char unused:3;
};
unsigned char raw;
} flags_t;