﻿# V2589\. MISRA\. Casts between a pointer and a non\-integer arithmetic type should not be performed\.

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 conversion between a non\-integer arithmetic type and a pointer may lead to undefined behavior\.

The MISRA C standard defines its own type model, called the [essential type model](https://pvs-studio.com/en/blog/terms/7007/)\.

The conversion between `essential Boolean`, `essential character`, or `essential enum` type and a pointer may result in a misaligned pointer, which, in turn, may lead to undefined behavior\.

The example:

```cpp
enum Nums
{
  ONE, 
  TWO,
  ....
};

double* bar(Nums num)
{
  ....
  return (double*)num;
}
```

The conversion between a pointer and essential types described above may result in a value unrepresentable within the destination essential type, which also may lead to undefined behavior\.

The example:

```cpp
void foo(void)
{
  ....
  char *a = "something";
  char b = a;
  ....
}
```

The conversion between the `essential floating` type and a pointer may lead to undefined behavior\.

The example:

```cpp
void foo(short *p)
{
  // ....
  float f = (float) p;
  // ....
}
```