[previous] 3400 [next] Extra parentheses recommended. A binary 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, the operand of a logical && or || operator is the result of some other binary operator.

The function of this message is to provide enforcement (along with messages 3398 and 3399) 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 2017,3120,3198,3199,3203,3397,3401,3408,3447 ++*/

extern int   a;
extern int   b;
extern int   c;

extern void foo(void)
{
    int r;

    r = a && b && c;                    /* OK */
    r = a || b || c;                    /* OK */
    r = (a > 200) && c;                 /* OK */

    r = a && b || c;                    /* Message 3400 */
    r = (a && b) || c;                  /* OK           */

    r = a || b && c;                    /* Message 3400 */
    r = (a || b) && c;                  /* OK           */

    r = a > 200 && c;                   /* Message 3400 */
    r = (a > 200) && c;                 /* OK           */

    r = a && b != c;                    /* Message 3400 */
    r = a && (b != c);                  /* OK           */
}


MISRA-C:2004 Rules applicable to message 3400:

Rule  12.5  (Required) The operands of a logical && or || shall be primary-expressions.


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