10.1 violated

6.6 Types

Moderators: misra-c, david ward

minnu
Posts: 1
Joined: Tue Jul 07, 2015 8:18 am
Company: mistra

10.1 violated

Postby minnu » Wed Jul 08, 2015 6:34 am

#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

misra-c
Posts: 547
Joined: Thu Jan 05, 2006 1:11 pm

Re: 10.1 violated

Postby misra-c » Wed Aug 05, 2015 8:59 am

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.
---
Posted by and on behalf of
the MISRA C Working Group


Return to “6.6 Types”

Who is online

Users browsing this forum: No registered users and 1 guest