kapilddit
kapilddit

Reputation: 1769

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

Upvotes: 1

Views: 10374

Answers (1)

kapilddit
kapilddit

Reputation: 1769

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.

Upvotes: 0

Related Questions