CIUCFL - Complex Initialization or Update Clause in for Loop
Go Up to C++ Audits
Description
When using the comma operator in the initialization or update clause of a for statement, avoid the complexity of using too many variables. The maximum number of variables is set by the Maximum option in the audit properties. By default, it is 3.
Depending on the detected problem, the CIUCFL audit can generate the following messages:
- %d variables initialize in the FOR loop. Maximum is %d
- %d variables update in the FOR loop. Maximum is %d
Incorrect:
for (i = 0, j = 0, k = 10, l = -1; i < size; i++, j++, k--, l += 2) {
...
}
Correct:
l =- 1;
for (i = 0, j = 0, k = 10; i < size; i++, j++, k--) {
...
l += 2;
}