﻿# V2544\. MISRA\. The values used in expressions should have appropriate essential types\.

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/)\.

The values used in expressions should have appropriate essential types\.

The C language has no restrictions on operations with basic types, but some of these operations may lead to unspecified/undefined behavior, or make no sense at all\.

For example:

* obtain a value in an array using a `Boolean` type index;
* try to change the sign of an unsigned integer;
* work with a bit representation using variables of non\-unsigned type\.

Implicit conversion to `Boolean` may also be dangerous, since not all decimals may be represented in the binary number system\.

```cpp
void Foo(float f, _Bool other_expr)
{
  if (f || other_expr) ....
}
```

The following table gives intersections of operands and operations types, which should not be composed in expressions\. These intersections are marked with an `X`\.

![V2544/image1.png](https://import.viva64.com/docx/blog/V2544/image1.png)

The example:

```cpp
void Foo(float f, _Bool b, int a[], enum E e)
{
  if (~a[(e ? 1 : 2) >> (-b * f --> +b) << signed(-24U)]) ....;
}
```

**Exception\.** Expression of a signed type with a positive value can be used as the right\-hand operand of a shift operator \(`>>`, `<<`\)\.

```cpp
void foo(signed vi, unsigned _)
{
  assert(vi >= 0);
  _ >> vi; 
  _ << vi;
}
```