This diagnostic rule is based on the software development guidelines developed by MISRA (Motor Industry Software Reliability Association).
This diagnostic rule is only relevant for C. Values of the essential character type should not be used in arithmetic expressions.
The MISRA standard defines the following essential type model, in which a variable may have a type:
There are no pointers in this model.
According to the essential type model, essential character type values mustn't be used in arithmetic expressions, as they are represented by a non-numerical type.
Let's see the list of correct ways of using character-type variables in arithmetic expressions:
An example of the code for which the analyzer will issue warnings:
void foo(char ch, unsigned ui, float f, _Bool b, enum A eA)
{
ch + f; // Essential character type should not be used in
// the addition operation with expression
// of the essential floating type
ch + b; // Also relates to the essential Boolean
ch + eA; // Also relates to the essential enum <A> type
(ch + ui) + (ch - 6); // After the expressions in parentheses
// have been executed, both operands of the
// essential character type are used
// in addition operation
}
This diagnostic is classified as:
|