Skip to main content

IAR Embedded Workbench for Arm 9.70.x

CERT-ARR36-C_b

In this section:
Synopsis

Do not compare two pointers that do not refer to the same array.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Do not subtract or compare two pointers that do not refer to the same array. This check is identical to MISRAC2004-17.3, MISRAC2012-Rule-18.3.

Coding standards
CERT ARR36-C

Do not subtract or compare two pointers that do not refer to the same array

MISRA C:2004 17.3

(Required) >, >=, <, <= shall not be applied to pointer types except where they point to the same array.

MISRA C:2012 Rule-18.3

(Required) The relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same object

Code examples

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

void example(void) {
  int a[10];
  int b[10];
  int *p1 = &a[1];
  if (p1 < b) {

  }
}

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

void example(void) {
  int a[10];
  int b[10];
  int *p1 = &a[1];
  if (p1 < a) {
  
  }
}