Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2023-8.2.5 (C++ only)

In this section:
Synopsis

(Required) reinterpret_cast shall not be used

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Use of reinterpret_cast may cause undefined behaviour

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 S1 { int n; };
struct S2 { int n; };

void example() {
  S1 s1;
  S2* s2 = reinterpret_cast<S2*>(&s1); // Non-compliant
}

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

struct S1 { int n; };

void example() {
  S1 s1;
  void* ptr = reinterpret_cast<void*>(&s1); // Compliant
}