Skip to main content

IAR Embedded Workbench for Arm 9.70.x

CERT-EXP39-C_c

In this section:
Synopsis

Do not access a variable through a pointer of an incompatible type.

Enabled by default

Yes

Severity/Certainty

Medium/Low

mediumlow.png
Full description

Modifying a variable through a pointer of an incompatible type (other than unsigned char) can lead to unpredictable results. This check is identical to MISRAC2012-Rule-11.2.

Coding standards
CERT EXP39-C

Do not access a variable through a pointer of an incompatible type

MISRA C:2012 Rule-11.2

(Required) Conversions shall not be performed between a pointer to an incomplete type and any other type

Code examples

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

struct a;
struct b;
void example(void) {
  struct a * p1;
  struct b * p2;
  unsigned int x;
  p1 = (struct a *) 0x12345678;
  x = (unsigned int) p2;
  p1 = (struct a *) p2;
}

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

#include <stdlib.h>

struct a;
extern struct a *f (void);

void example(void) {
  struct a * p;
  unsigned int x;
  /* exception 1: NULL -> incomplete type ptr */
  p = (struct a *) NULL;
  /* exception 2: incomplete type ptr -> void */
  (void) f();
}