Why is this an issue?
The comma operator takes two expressions, executes them from left to right and returns the result of the second one. Use of this operator is
generally detrimental to the readability and reliability of code, and the same effect can be achieved by other means.
Noncompliant code example
i = a += 2, a + b; // What's the value of i ?
Compliant solution
a += 2;
i = a + b;
Exceptions
Use of comma operator is tolerated:
- in initialization and increment expressions of
for
loops.
for(i = 0, j = 5; i < 6; i++, j++) { ... }
- If the expression sequence is explicitly wrapped in parentheses.