Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2004-17.4_b

In this section:
Synopsis

(Required) Array indexing shall be the only allowed form of pointer arithmetic.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Array indexing was detected applied to an object defined as a pointer type. This check is identical to MISRAC++2008-5-0-15_b.

Coding standards
MISRA C:2004 17.4

(Required) Array indexing shall be the only allowed form of pointer arithmetic.

MISRA C++ 2008 5-0-15

(Required) Array indexing shall be the only form of pointer arithmetic.

Code examples

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

typedef unsigned char UINT8;
typedef unsigned int UINT;

void example(UINT8 *p, UINT size) {
  UINT i;
  for (i = 0; i < size; i++) {
    p[i] = 0;
  }
}

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

typedef unsigned char UINT8;
typedef unsigned int UINT;

void example(void) {
  UINT8 p[10];
  UINT  i;
  for (i = 0; i < 10; i++) {
    p[i] = 0;
  }
}