Rule 12.4 - Do not use expressions with side effects - 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.12 Expressions (https://forum.misra.org.uk/forumdisplay.php?fid=39) +---- Thread: Rule 12.4 - Do not use expressions with side effects (/showthread.php?tid=990) |
Rule 12.4 - Do not use expressions with side effects - jbrookley - 24-10-2013 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 Re: Rule 12.4 - Do not use expressions with side effects - Steve Montgomery - 25-10-2013 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 Re: Rule 12.4 - Do not use expressions with side effects - jbrookley - 28-10-2013 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! Re: Rule 12.4 - Do not use expressions with side effects - misra-c - 13-12-2013 We feel that Steve has given a good response to this question and have nothing more to add. |