Clarification of Exception for Rule 10.4 - 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: Clarification of Exception for Rule 10.4 (/showthread.php?tid=985) |
Clarification of Exception for Rule 10.4 - rgamble - 26-09-2013 The first exception to rule 10.4 states: Quote:The binary + and += operators may have one operand with essentially character type and the In the examples, the following is specified as being compliant per this exception, as expected: Code: cha += u8a However, the following is later included in a list of examples that are non-compliant: Code: 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? Re: Clarification of Exception for Rule 10.4 - Steve Montgomery - 01-10-2013 I agree with your reasoning and I suspect that this is a mistake in the document. However, although the example Code: u8a += cha So, I think that this expression still wouldn't be acceptable under MISRA C:2012 but for a different reason. Re: Clarification of Exception for Rule 10.4 - misra-c - 12-11-2013 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. |