﻿# 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](https://www.misra.org.uk/) \(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](https://pvs-studio.com/en/blog/terms/7007/)\.

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:

1. **Addition**: one operand should have a character type, another one should have signed or unsigned integer type\. The result of such operation has the character type:
    * `character` \+ `[un]signed` \=\> `character`
    * `[un]signed` \+ `character` \=\> `character`
1. **Subtraction**: the left operand should have a character type, and the right operand should have signed or unsigned integer type\. The result of this operation will be a value of character type:
    * `character` \- `[un]signed` \=\> `character`
1. **Subtraction**: both operands should have a character type\. The result of the operation will be a value of signed integer type:
    * `character` \- `character` \=\> `signed`

The example:

```cpp
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
}
```