Short-circuit evaluation
- Posted by rforno at tutopia.com Aug 09, 2002
- 403 views
Rob: I know, it is seldom used and impractical, but have you thought about extending short-circuit evaluation to the operations I mention below? I was thinking about this only regarding educational purposes: you know there are 16 possible binary Boolean operations with 2 operands. Some comparison operations can be used in a Boolean context. For example, XOR is not needed at the variable-level because it may be substituted by !=. The operations I was thinking of are: if (a > b) >= (x = z) then ... If a > b is true, then there is no need to evaluate x = z. if (c <= u) > ( d > g) then... If c <= u is false, then there is no need to evaluate d > g and similarly with <= and <. These operations, when used with Boolean operands, might be thought about as "implication", etc. = and != cannot be short-circuited. AFAIK, C doesn't use this little trick. Regards.