Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2589. MISRA. Casts between a...
menu mobile close menu
Additional information
toggle menu Contents

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

Aug 25 2025

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 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.

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:

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:

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:

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

This diagnostic is classified as:

  • MISRA-C-2012-11.7
  • MISRA-C-2023-11.7