MISRA C:2012 Rule 10.2
Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations
Description
Rule Definition
Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations1 .
Rationale
Essentially character type expressions are char variables. Do not use
          char in arithmetic operations because the data does not represent
        numeric values.
It is appropriate to use char with addition and subtraction
        operations only in the following cases:
- When one operand of the addition (+) operation is a - charand the other is a signed or unsigned- char,- short, or- int. In this case, the operation returns a- char.
- When the first operand of the subtraction (-) operation is a - charand the second is a signed or unsigned- char,- short, or- int. If both operands are- char, the operation returns a standard type. Otherwise, the operation returns a- char.
The above uses allow manipulation of character data such as conversion between lowercase and uppercase characters or conversion between digits and their ordinal values.
For more information on essential types, see Essential Types in MISRA C Rules 10.x.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: The Essential Type Model | 
| Category: Required | 
| AGC Category: Advisory | 
Version History
See Also
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
- MISRA C:2004 
- MISRA C:2012 
- MISRA C:2023 
- MISRA C++:2008 
- MISRA C++:2023 
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.