Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 12.4 - Do not use expressions with side effects
#1
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
<t></t>
Reply
#2
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
<t></t>
Reply
#3
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!
<t></t>
Reply
#4
We feel that Steve has given a good response to this question and have nothing more to add.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)