...
However, since comparison binds tighter than assignment, the value of the comparison is stored in ret. So if foo() succeeds, ret will always be set to 0, and the if-statement will execute if and only if foo() fails, contrary to the expectation of exactly opposite of what the programmer expects.
Compliant Solution
| Code Block | ||
|---|---|---|
| ||
if((ret = foo()) != err) {
/* use ret */
}
|
...