MISRA Discussion Forums

Full Version: Rule 17.4 - array elements contained inside structure def
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
• 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?
This code does not violate Rule 17.4. Array elements within a structure can be accessed in this manner.