[previous] 3415 [next] Right hand operand of '&&' or '||' is an expression with possible side effects.
Side Effects REFERENCE - ISO:C90-5,1,2,3 Program Execution

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:

However QA·C 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

For example:


/*PRQA S 2017,3199,3227,3398,3408,3440,3447 ++*/

extern int func1(void);
extern int func2(void);

#pragma PRQA_NO_SIDE_EFFECTS func2

extern void foo(int x, int y)
{

    if ((x > 0) && (y++ < 0))           /* Messages 3415 and 3416 */
    {
    }

    if ((x > 0) && func1())             /* Messages 3415 and 3416 */
    {
    }

    if ((x > 0) && func2())             /* No message - no side effects */
    {
    }
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents