MISRA Discussion Forums
Rule 10.3 Does exception 1 apply to case labels? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.10 The essential type model (https://forum.misra.org.uk/forumdisplay.php?fid=165)
+---- Thread: Rule 10.3 Does exception 1 apply to case labels? (/showthread.php?tid=1206)



Rule 10.3 Does exception 1 apply to case labels? - grunwald - 15-10-2015

Rule 10.3 covers assignment (as defined in the glossary) and the conversion of the constant expression in case labels.

Exception 1 says "A non-negative integer constant expression of essentially signed type may be assigned to an object of essentially unsigned type if its value can be represented in that type."

Is this exception intended to be restricted to assignment; or does it also apply to case labels?

Code:
switch (u8a) // controlling expression is essentially unsigned
{
    case 1: break; // '1' is essentially signed; 10.3 violation?
    case 2: break;
    default: break;
}



Re: Rule 10.3 Does exception 1 apply to case labels? - misra-c - 06-11-2015

The intent of the MISRA-C working group was that Exception 1 should also apply to conversions on a switch statement’s case label.

This will be clarified in the forthcoming Technical Corrigendum and your example should be considered compliant with rule 10.3.