Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC++2008-5-2-6

In this section:
Synopsis

(Required) A cast shall not convert a pointer to a function to any other pointer type, including a pointer to function type.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A cast shall not convert a pointer to a function to any other pointer type, including a pointer to function type. This check is identical to MISRAC++2023-8.2.4.

Coding standards
MISRA C++ 2023 8.2.4

(Required) Casts shall not be performed between a pointer to function and any other type

Code examples

The following code example fails the check and will give a warning:

#include <stdint.h>
void f ( int32_t )
{
  reinterpret_cast< void (*)( ) >( &f ); // Non-compliant
}

The following code example passes the check and will not give a warning about this issue:

#include <stdint.h>
void f ( int32_t )
{
  void (*fp)(int32_t) = &f;
}