[previous] 3399 [next] Extra parentheses recommended. A unary operation is the operand of a logical && or ||.
Readability

The order in which operators are processed in this expression is not sufficiently clear and so additional parentheses are recommended. In the absence of parentheses, the sequence is determined by rules of precedence and associativity.

In this case, an operand of a logical && or || operator is the result of some unary operator. Add parentheses around the operand to make it clear which operator is evaluated first.

The function of this message is to provide enforcement (along with messages 3398 and 3400) of Rule 12.5 in MISRA-C:2004. This rule requires that the operands of a logical && or || operator should be primary expressions.

For example:


/*PRQA S 506,2017,2211,3198,3199,3203,3408,3447,4109 ++*/

extern int           a;
extern int           b;
extern unsigned int  ua;
extern unsigned int  ub;
extern int          *pi;
extern long          rl;

extern void foo(void)
{
    int r;

    r = ua && ~ub;                      /* Message 3399 + 3390 */
    r = !a || b;                        /* Message 3399 + 3390 */
    r = *pi || b;                       /* Message 3399 + 3390 */
    r = a && (int)rl;                   /* Message 3399 + 3390 */
}

See also:

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