Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

However, since comparison binds tighter than assignment, the value of foo() != err 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, exactly opposite of what the programmer expects1, regardless of what foo() actually returned.

Compliant Solution

Code Block
bgColor#ccccff
if((ret = foo()) != err) {
  /* use ret */
}

...