Wiki Markup |
---|
Programmers frequently make errors regarding the precedence of operators due to the unintuitive low-precedence levels of {{&}}, {{\|}}, {{\^}}, {{<<}}, and {{>>}}. Avoid mistakes regarding precedence through the suitable use of parentheses; this also improves code readability, unless taken to excess. The precedence of operations by the order of the subclauses are defined in the Java Tutorials \[[Tutorials 2008|AA. Bibliography#Tutorials 08]\]. |
...
This expression gets evaluated, as shown below, resulting in the value 0.
...
Mistakes regarding precedence guidelines may can cause an expression to be evaluated in an unintended way. This can lead to unexpected and abnormal program behavior.
...
Detection of all expressions using low-precedence operators without parentheses is straightforward. Determining the correctness of such uses is infeasible in the general case; heuristic warnings may could be useful.
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this guideline on the CERT website.
Other Languages
Related Guidelines
This guideline appears in the C Coding Standard as : EXP00-C. Use parentheses for precedence of operation.This guideline appears
in the C++ Secure Coding Standard as : EXP00-CPP. Use parentheses for precedence of operation.
Bibliography
Wiki Markup |
---|
\[[ESA 2005|AA. Bibliography#ESA 05]\] Rule 65: Use parentheses to explicitly indicate the order of execution of numerical operators \[[Tutorials 2008|AA. Bibliography#Tutorials 08]\] [Expressions, Statements, and Blocks|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html], [Operators|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html] |
...