MISRA Discussion Forums

Full Version: Incorrect comment in mc2_1703.c
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
There is a comment regarding line:
Code:
else if ( ( &array_12 [ 12 ] - &array_12 [ index_1 ] ) > 0 )
The comment states that this line violates rule 17.4, which is not the case, as the variable array_12 has been declared as an array.
It should state that there is a violation of rule 21.1 regarding array bound errors.
The array has 12 elements so it is valid to take the address of array_12[12] because the standard permits taking the address of the element one beyond the end of an array.

The code in the example file ensures that index_1 is in the range 0 to 11. Therefore, both array indices are valid at least for the purposes of taking addresses.

Rule 17.4 prohibits all pointer arithmetic including subtraction of pointers even if they point into the same array.