[previous] 3398 [next] Extra parentheses recommended. A function call, array subscript, or member 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 expression, an operand of a logical && or || operator is the result of a function call, an array subscript operation, or the result of a structure/union member operation -> or .. 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 3399 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,2213,2216,3132,3198,3199,3203,3227,3408,3416,3447 ++*/

struct S { int x; int y; } ;

extern int        fx(int x);
extern struct S   st;
extern struct S * pst;
extern int        buf[100];

extern void foo(int a, int b)
{
    int r;

    r = buf[a] && b;                    /* Message 3398 + 3390 */
    r = (buf[a]) && b;                  /* OK                  */

    r = fx(a) || b;                     /* Message 3398 + 3390 */
    r = (fx(a)) || b;                   /* OK                  */

    r = pst->x && a;                    /* Message 3398 + 3390 */
    r = (pst->x) && a;                  /* OK                  */

    r = st.x || b;                      /* Message 3398 + 3390 */
    r = (st.x) || b;                    /* OK                  */

}

See also:

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