I just thought about the possibility for the less-than and-greater than operators to short-circuit. That is, they can skip evaluating their second operand if the value of the second operand logically makes no impact on the overall result. Short-circuit evaluation is generally limited to logical OR and logical AND, because for OR, if the first operand is true, the result will be true regardless the value of the second operand, so it does not need to be evaluated. Similar goes for logical AND.
However, what if the first operand of a less-than-or-equal happens to be the minimum value of a type? Or if the first operand of a greater-than happens to be said minimum value? In these cases, there is no value of the second operand that will make the value anything other than true or false respectively. Here are more examples:
INT_MIN <= x; // true
INT_MIN > x; // false
INT_MAX >= x; // true
INT_MAX < x; // false
Note that here INT_MIN
or INT_MAX
indicate the values at runtime, not compile-time constants.
These expressions will hold no matter the value of X. So why is it that no language I have know of seems to have short-circuiting behavior for relational comparisons?
b = INT_MIN <= ;
instead of eitherb = true ;
orb = INT_MIN <= x;
? Or do you simply want the result to be computed at compile time? $\endgroup$INT_MIN
etc. No where in the question did I say the left-hand operands were constants. $\endgroup$