Rule 17.4 - array elements contained inside structure def - 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 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.17 Pointers and Arrays (https://forum.misra.org.uk/forumdisplay.php?fid=44) +---- Thread: Rule 17.4 - array elements contained inside structure def (/showthread.php?tid=935) |
Rule 17.4 - array elements contained inside structure def - sshidore - 21-01-2013 • MISRA C rule 17.4 says arithmetic operations shall not be performed on pointers, as they may result into referencing to non-existing addresses. • Alternative to this is to catch a pointer being received as an argument into the respective type of an array, for e.g. catch ‘&arr’ into ‘arr[]’, and use array indexing to access its elements. This works well for pointers of basic data types. • Problem arises in the case of accessing array elements contained by a structure. • e.g. struct message { int address; int length; int data[50]; }m1,m2; • Now, the statement “source_node = m1.data[SOURCE_NODE_INDEX]†triggers this 17.4 non-compliance note. • This happens when accessing only the array elements, and not for single variables of a structure definition. • So the question I have is, what is the best way to access individual array elements contained inside a structure definition? Re: Rule 17.4 - array elements contained inside structure de - misra-c - 29-01-2013 This code does not violate Rule 17.4. Array elements within a structure can be accessed in this manner. |