06-11-2023, 01:19 PM
The intent of the rule is to enforce the interpretation that plain chars are used for characters, whereas signed/unsigned chars are meant to represent numeric values.
The exceptions exist because, at some point there is likely to be a requirement to input a string and interpret it as an integer (hence the allowed comparison with characters '0'..'9' and subtraction of '0'). Similarly, during output, converting an integer between 0..9 to a char requires adding '0'.
This rule does not apply to uint8_t, as there is no ambiguity in its range - unlike plain char which may be 0..255 or -128..127
The exceptions exist because, at some point there is likely to be a requirement to input a string and interpret it as an integer (hence the allowed comparison with characters '0'..'9' and subtraction of '0'). Similarly, during output, converting an integer between 0..9 to a char requires adding '0'.
This rule does not apply to uint8_t, as there is no ambiguity in its range - unlike plain char which may be 0..255 or -128..127
Posted by and on behalf of
the MISRA C++ Working Group
the MISRA C++ Working Group