Rule 10.3 Does exception 1 apply to case labels?

Moderators: misra-c, david ward

Post Reply
grunwald
Posts: 15
Joined: Wed May 14, 2014 1:02 pm
Company: Axivion GmbH

Rule 10.3 Does exception 1 apply to case labels?

Post by grunwald » Thu Oct 15, 2015 1:30 pm

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: Select all

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

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

Re: Rule 10.3 Does exception 1 apply to case labels?

Post by misra-c » Fri Nov 06, 2015 11:40 am

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

Post Reply

Return to “8.10 The essential type model”