Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC2012-Rule-18.4

In this section:
Synopsis

(Required) The +, -, += and -= operators should not be applied to an expression of pointer type.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A +, -, +=, or -= operator was found applied to an expression of pointer type.

Coding standards
MISRA C:2012 Rule-18.4

(Advisory) The +, -, += and -= operators should not be applied to an expression of pointer type

Code examples

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

void example(int *ptr) {
  int a = *(ptr + 1);
}

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

void example(int *ptr) {
  int a = ptr[1];
}