Let's say I have a C structure defined as
struct data {
/* some memebers */
int flag_a:1;
int flag_b:1;
int flag_c:1;
/* some other members */
}
Is there a way to take advantage of the bitfields being represented as a single int in memory and write the condition s.flag_a | s.flag_b | s.flag_c
as a simpler expression such as s.flags
?
Or would a smart compiler such as GCC be able to actually deduce it?
Edit: To make myself absolutely clear: I'm looking for a portable way to test for all the flags being set without explicitly testing each of the flags separately.