MISRA Discussion Forums

Full Version: Rule 12.4 - Do not use expressions with side effects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I am having a problem with rule 12.4 (Do not use expressions with side effects in the right hand operand of a logical '&&' operator). My code is as follows:

[code]if ((DualDAC == 0) && (ADC1Flag
I'm assuming that ADC1Flag has a volatile qualified type so that the act of reading its value it is a side-effect. That being the case, I think you have only two options: either nest the tests (as you did in your proposed solution), or perform the volatile access first, e.g.

[code]flag = ADC1Flag
So glad I posted here, I didn't understand WHY this was happening. While it's kind of a bummer to need a nested if loop, codewise, apparently, it's the same size so it's not a huge deal. Thanks for your help!
We feel that Steve has given a good response to this question and have nothing more to add.