MISRA Discussion Forums
Incorrect comment in mc2_1703.c - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C:2004 Exemplar Suite (https://forum.misra.org.uk/forumdisplay.php?fid=116)
+--- Thread: Incorrect comment in mc2_1703.c (/showthread.php?tid=583)



Incorrect comment in mc2_1703.c - Graham Andrews - 17-09-2008

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.


Re: Incorrect comment in mc2_1703.c - misra-c - 02-06-2009

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.