简体   繁体   中英

Right hand operand of '&&' or '||' is an expression with possible side effects

Code statement look like below:

if((temp1 == ID1) || (temp2 == (C_UINT16) ID2))
{

}

I am not sure why QAC is generating this warning. What will be the side effect & how to avoid this warning.

Details for QAC-help:

The right hand operand of a logical && operator is only evaluated if the left hand operand evaluates to 1 ("true"). The right hand operand of a logical || operator is only evaluated if the left hand operand evaluates to 0 ("false").

Because of this behaviour, confusion can arise if the right hand operand of either of these operators generates side effects. Message 3415 is generated to identify such a situation.

Side effects occur when an expression:

  1. accesses a volatile object
  2. executes an increment, decrement, assignment or compound assignment operation
  3. performs I/O or
  4. calls a function which does any of the above

However QAC assumes that side effects occur whenever a function is called, unless the function has specifically been identified as being free from side effects by a #pragma statement of the form:

#pragma PRQA_NO_SIDE_EFFECTS funcname

While looking at variable temp1 & temp2. I got to know it is declared as volatile. After changing the variable to the normal non-volatile, the warning is not observed. It was level 4 warning in QAC.

Reference: https://cboard.cprogramming.com/c-programming/68666-strange-side-effects.html

Another way to resolve the error to read the volatile variable again before performing the operation again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM