[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 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

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 */
}


No MISRA-C:2004 Rules applicable to message 3446


See also:

QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents