V2543. MISRA. Value of the essential character type should be used appropriately in the addition/subtraction operations.

This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.

This diagnostic rule is relevant only for C.

The MISRA C standard defines its own type model, called the essential type model.

According to the essential type model, essential character type values should not be used in arithmetic expressions, since they are represented as a non-numerical.

Here is the list of correct ways of using character-type variables in arithmetic expressions:

The example:

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:

  • MISRA-C-2012-10.2
  • MISRA-C-2023-10.2