Is underlining valid for shortcuts?

In some header file that I cannot change, I have the following set of definitions:

#define FLAG1                      (0x0000_0001)
#define FLAG2                      (0x0000_0002)
...

Then in my code I use them in switch:

switch (aaa) {
    case FLAG1:
    ....

    case FLAG2:
    ....
}

As a result, Coverity reports two defects per case label:

RW.EXP_RPAREN: 
Event exp_rparen: expected a ")"

RW.CASE_LABEL_CONFLICT:
Event case_label_conflict: case label value has already appeared in 
this switch at line XX

What is wrong with these shortcuts? Does it violate C standards?

+5
source share
3 answers

Yes, this is the underline that causes problems. FWIW, here are the relevant sections from the C language standard (draft n1256 ):

  • & ; 6.4.4.1 : , _ ;
  • & ; 6.6 : ;
  • & ; 6.8.4.2 switch: case switch.
+3

, . , , - , 0x0000_0001.

, , , _.

+5

, ), _, .

:

error: invalid suffix "_0001" on integer constant

case :

switch(number) {
    // no way to determine operator 
    // precedence without parens here
    case 2*(1+2):
}
+2
source

All Articles