I recently noticed that the following expression compiles in my compiler (Clang):
float a;
if (0.0 < a < 1.0) { ... }
Does this do wh
Does this do what I expect?
No, it does
(0.0 < a) < 1.0
and (0.0 < a) yields 0 or 1. So you end up having 0 < 1.0 or 1 < 1.0 evaluated.
Note that in some other languages it does what you expect.
For example in Python,
a < b < c
is called a chained comparison and it is equivalent to:
(a < b) and (b < c)