Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2004-17.3

In this section:
Synopsis

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

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A relational operator was found applied to an object of pointer type that does not point into the same object. This check is identical to MISRAC2012-Rule-18.3, CERT-ARR36-C_b.

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) {
  
  }
}