MISRA Discussion Forums

Full Version: 10.1 violated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
#define NUM 9u
#define NUM2 8

/* gus32cmd is keyboard entry .numbers from 1 to 10*/

scanf("%d", &gus32cmd );


case NUM2


At lines case:NUM and case NUM2 I got following misra c error

"Rule 10.1 violated "implicit conversion of complex integer expression to a small sized integer is not allowed"
What correction I should do to avoid this error
The value of the case expression is implicitly converted to the type of the switch chooser ( C90 section This implicit conversion is checked by rule 10.1.

The type of the switch chooser (gus32cmd) is not given in this example, but must be either signed or unsigned. If gus32cmd is signed, then "case NUM" will violate rule 10.1 as they have different signs. If gus32cmd is unsigned, then "case NUM2" will violate rule 10.1 as again the signs are different.