What is a pitfall?

C++ code that
  • compiles
  • links
  • runs
  • does something different than you expect
Example:
if (-0.5 <= x <= 0.5) return 0;
Pitfall:
if (-0.5 <= x <= 0.5) return 0;
This expression does not test the mathematical condition
-1.5 <= x <= 1.5
Instead, it first computes -0.5 <= x, which is 0 or 1, and then compares the result with 0.5.
Moral: Even though C++ now has a bool type, Booleans are still freely convertible to int.
Since bool->int is allowed as a conversion, the compiler cannot check the validity of expressions. In contrast, the Java compiler would flag this statement as an error.