[previous] 3446 [next] The 2nd or 3rd operand of this conditional operator is an expression with possible side effects.
Side Effects

Evaluation of this conditional operator may induce side effects.

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

The conditional operator is often a source of confusion. If side effects are involved, it may be wiser to use an if statement.

For example:


/*PRQA S 3198,3199,3227,3396,3408,3440,3447 ++*/

extern int fn(void);
extern int r;

extern void foo(int a, int b)
{
    r = ( a > 0 ) ? b : a++;                    /* Message 3446 */
    r = ( a > 0 ) ? fn() : b;                   /* Message 3446 */

    r = ( a++ > 0 ) ? b : (b + 1);              /* Message 3416 */
}

See also:

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