Reputation: 11
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.
Upvotes: 0
Views: 230
Reputation: 214780
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 of buf
aren't sequenced in relation to each other but it should not matter in this case.
Other MISRA rules enforce the use of volatile
qualified 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 * volatile
qualifier on the pointer makes things further complex - you might have to get rid of that one first through a separate assignment
Also keep in mind that TmpSize = buf[0u];
is equivalent to TmpSize = *(buf+0u);
. This might be what the tool is upset about. You could simply try to change the code to TmpSize = *buf;
and see if that changes anything.
volatile uint32_t* tmp_ptr = buf;
uint32_t tmp_size = *tmp_ptr;
Upvotes: 0