Page 1 of 1

10.1 violated

Posted: Wed Jul 08, 2015 6:34 am
by minnu
#define NUM 9u
#define NUM2 8


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

scanf("%d", &gus32cmd );

Switch(gus32cmd)
{
case:NUM
....
....
break;


case NUM2
..
..
break;

}

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

Re: 10.1 violated

Posted: Wed Aug 05, 2015 8:59 am
by misra-c
The value of the case expression is implicitly converted to the type of the switch chooser ( C90 section 6.6.4.2). 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.