October 26, 2024
Chicago 12, Melborne City, USA
C#

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



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video