Synopsis: | The convenience of the conditional operator should be weighed against the clarity of the code. |
Language: | C |
Severity Level: | 7 |
Category: | EXPRESSIONS |
Description: |
The interaction of the conditional operator with the precedence of other operators causes confusion for many novice programmers. If the second or third operand is a non-atomic expression it is clearer to use an if statement instead of the ? : operators. Hence, Example: len = (ac_DataLength <= 3) ? ac_DataLength : 3; is allowed, but the following construction is not accepted. Example: len = (ac_DataLength <= 3) ? (ac_DataLength + 1) : 3; |