[previous] 3397 [next] Extra parentheses recommended. A binary operation is the operand of a binary operator with different precedence.
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, one of the operands of a shift, relational, equality, bitwise or logical operator is a binary expression formed from an operator of higher precedence. Add parentheses to make it clear which operator is evaluated first.

For example:


/*PRQA S 502,2017,3198,3199,3203,3401,3408,3447,4105,4130 ++*/

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

extern void foo(void)
{
    int r;

    r = a + b >> c;                     /* Message 3397 + 3390 */
    r = (a + b) >> c;                   /* OK                  */

    r = a < b + 1;                      /* Message 3397 + 3390 */
    r = a < (b + 1);                    /* OK                  */

    r = a & b != 1;                     /* Message 3397 + 3390 */
    r = a & (b != 1);                   /* OK                  */

}


MISRA-C:2004 Rules applicable to message 3397:

Rule  12.1  (Advisory) Limited dependence should be placed on C's operator precedence rules in 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