This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

bit field

Hi All,

I have a struct:

   union U
   {
      unsigned char c;
      struct
      {
         unsigned char bit0 : 1;
         unsigned char bit1 : 1;
         unsigned char bit2 : 1;
         .
         .
         .
      }S;
   };
}
If I test multiple bits together I would have to do something like:
if (S.bit0 || S.bit1 || S.bit2)
which might generate insufficient code.

I can group multiple bits together but that would require changing the bitfields all the time as the code changes.

if I used bit mask instead of bit field. It would be something like:
if (var & (BIT_0 | BIT_1 | BIT2))
which generates much better code.

Is there anyway to makeit more efficient testing mutiple bit fields in 1 shot?

Thanks,

Anh

0