MISRAC2004-17.4_a
In this section:
Synopsis
(Required) Array indexing shall be the only allowed form of pointer arithmetic.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Pointer arithmetic that is not array indexing was detected. This check is identical to MISRAC++2008-5-0-15_a.
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 int INT32;
void example(INT32 array[]) {
INT32 *pointer = array;
INT32 *end = array + 10;
for (; pointer != end; pointer += 1) {
*pointer = 0;
}
}
The following code example passes the check and will not give a warning about this issue:
typedef int INT32;
void example(INT32 array[]) {
INT32 index = 0;
INT32 end = 10;
for (; index != end; index += 1) {
array[index] = 0;
}
}