In some header file which I can not modify I have the following set of defines:
#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 on 2 defects per each 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 case labels? Does it violate C standards?
Yes, you are allowed to have parentheses. What you aren't allowed to have is a number like 0x0000_0001
.
That's not a valid hex number, you'll probably have to remove the _
character.
Yeah, it's the underscore that's causing problems. FWIW, here are the relevant sections from the C language standard (draft n1256):
_
is not a valid character for an integer constant;switch
statement: defines the restrictions on case
labels in a switch
statement. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With