Clarification of Exception for Rule 10.4

Moderators: misra-c, david ward

Post Reply
Posts: 14
Joined: Fri Jul 20, 2007 7:54 pm

Clarification of Exception for Rule 10.4

Post by rgamble » Thu Sep 26, 2013 9:24 pm

The first exception to rule 10.4 states:
The binary + and += operators may have one operand with essentially character type and the
other operand with an essentially signed or essentially unsigned type;
In the examples, the following is specified as being compliant per this exception, as expected:

Code: Select all

cha += u8a
However, the following is later included in a list of examples that are non-compliant:

Code: Select all

u8a += cha
How can the first one be compliant and the second one not be? Was the intention of the exception that the first operand have essentially character type and the second have signed or unsigned type? Or is the example incorrect?

Steve Montgomery
Posts: 104
Joined: Fri Sep 17, 2004 1:31 pm
Company: .
Location: Northumberland or Isle of Skye

Re: Clarification of Exception for Rule 10.4

Post by Steve Montgomery » Tue Oct 01, 2013 12:35 pm

I agree with your reasoning and I suspect that this is a mistake in the document.

However, although the example

Code: Select all

u8a += cha
should probably be compliant with Rule 10.4, I believe that it would break Rule 10.3 because the RHS of the assignment would be essentially character but the LHS would be essentially unsigned.

So, I think that this expression still wouldn't be acceptable under MISRA C:2012 but for a different reason.

Posts: 572
Joined: Thu Jan 05, 2006 1:11 pm

Re: Clarification of Exception for Rule 10.4

Post by misra-c » Tue Nov 12, 2013 12:43 pm

The examples can be expanded as follows:
cha += u8a is the same as cha = cha + u8a
u8a += cha is the same as u8a = u8a + cha

Appendix D ("Addition with char) shows that the essential type of the right hand side of both of these expressions is Essentially character, meaning that the first assignment is permitted but the second is not as it violates Rule 10.2.

The document is incorrect in that it should state that u8a+=cha is compliant with exception 1 of rule 10.4, but violates rule 10.3.
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.10 The essential type model”