Parentheses in logical expressions
ID | STAT-8 |
Title | Use parentheses to clarify precedence in logical expressions. |
Priority | Strongly recommended |
Severity level | 5 |
Description | Use parentheses to clarify the precedence of operands in expressions with multiple logical operators. No parentheses are required when only one type of logical operator is used. For example: d = a && b && c; . |
Rationale | By clarifying the precedence of the operands in such expressions, readability is improved and unexpected behaviour is prevented. |
Avoid:
d = a && b || c;
Instead use:
d = (a && b) || c;