# V2568. MISRA. Both operands of an operator should be of the same type category.

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.

Converting arithmetic operands which essential types are not consistent may lead to non-obvious issues.

The C language allows much flexibility in conversions between arithmetic types, but they can also result in hidden problems such as loss of sign, loss of value, or loss of precision. Despite its strictness, the MISRA C standard does allow conversions between arithmetic types when the operands have the same essential types.

Exception. The essential types of the left and right operands of the `+`, `-`, `+=`, and `-=` operators can be `character` and `signed`/`unsigned` respectively.

The example:

    enum { A };
    int i;
    unsigned u;
    void foo()
    {
      A + u;
      0.f - i;
      A > (_Bool)0;
    }

The fixed code:

    void foo(unsigned short x, _Bool b)
    {
      x + 1UL;
      if (b && x > 4U) ....
    }

This diagnostic is classified as:

MISRA-C-2012-10.4 MISRA-C-2023-10.4