Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
1-bit bitfield in boolean expression
#1
Hi,
rule 13.2 makes an example how boolean data could be used in an expression:
Code:
if ( y ) /* Not compliant, unless y is effectively Boolean data (e.g. a flag) */
The example refers to a Boolean-by-enforcement type referred to in the appendix.
But what is with a 1-bit Bitfield? Is it a Boolean-by-construct?
Code:
struct { unsigned int flag1: 1, flag2: 1;} var;
...
if (var.flag1)                   /* violation of rule 13.2 ? */
if (( var.flag1) && (var.flag2)) /* violation of rule 12.6 ? */
if ((!var.flag1) && (var.flag2)) /* 2x violation of rule 12.6 ? */
if ((var.flag1 == 0) && (var.flag2 != 0)) /* OK, but clumsy and harder to read */
Thanks for a comment!
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)