Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2008-5-2-8

In this section:
Synopsis

(Required) An object with integer type or pointer to void type shall not be converted to an object with pointer type.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Casting from integral types to pointer types can lead to unspecified behavior This check is identical to MISRAC++2023-8.2.6.

Coding standards

This check does not correspond to any coding standard rules.

Code examples

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

struct S { int i; };

void example(void * p1) {
  S* s1 = static_cast< S* >( p1 ); // Non-compliant
}

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

void example(void * p1) {
  auto p = const_cast< void const* >( p1 );  // Compliant
}