[previous] 3389 [next] Extra parentheses recommended to clarify the ordering of a % operator and another arithmetic operator (* / % + -).
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, the ordering of two operations needs to be clarified; one is a % operator and the other is a +, -, * or / operator or another %. Add parentheses to make it clear which operator is evaluated first.

For example:


/*PRQA S 584,2017,3103,3198,3199,3203,3401,3408,3447 ++*/

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


extern void foo(void)
{
    int r;

    r = a + b % c;        /* Message 3389 + 3390 */
    r = a + (b % c);      /* OK                  */

    r = a % b % c;        /* Message 3389 + 3390 */
    r = (a % b) % c;      /* OK                  */

    r = a % b * c;        /* Message 3389 + 3390 */
    r = (a % b) * c;      /* OK                  */

    r = a * b % c;        /* Message 3389 + 3390 */
    r = (a * b) % c;      /* OK                  */



}

See also:

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