I am not sure how to fix the fallowing MISRA error 13.2, The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders. I know the error is flag because buf is a volatile pointer. But I have no choice to declare it has volatile since his location in ram can change. I got the fallowing code
volatile uint32_t * volatile buf;
void function1()
{
uint32_t TmpSize;
TmpSize = buf[0u];
/*do something with TmpSize here*/
}
Can anyone help me with this.
Unspecified order of evaluation is only a problem in expressions where it matters. As the rule says, "the value should be the same under all permitted evaluation orders". The evaluation of
TmpSize(before assignment) and the evaluation ofbufaren't sequenced in relation to each other but it should not matter in this case.Other MISRA rules enforce the use of
volatilequalified variables not to get mixed with other unrelated operands. Your use here is therefore correct - copy the variable into a local temporary one and do other forms of arithmetic etc on that local copy from there.Now of course the
* volatilequalifier on the pointer makes things further complex - you might have to get rid of that one first through a separate assignmentAlso keep in mind that
TmpSize = buf[0u];is equivalent toTmpSize = *(buf+0u);. This might be what the tool is upset about. You could simply try to change the code toTmpSize = *buf;and see if that changes anything.