Skip to main content
4 events
when toggle format what by license comment
Oct 3, 2023 at 17:04 comment added Ben Voigt @peter: if (x != INT_MAX && x < foo()), the exceptional value for strict < is INT_MAX not INT_MIN
Oct 1, 2023 at 15:34 comment added Peter Cordes @kaya3: If I'm understanding correctly, that turns one comparison into two when evaluating on normal hardware. (Except when the RHS has no side-effects so compilers can skip the short-circuiting). if (x < foo()) would have to get compiled like C if (x != INT_MIN && x < foo()), with two compare-and-branch operations, the first one before a function call, the second after. This is horrible, and as your answer says, will take extra branch-prediction entries and isn't free for front-end throughput.
Oct 1, 2023 at 10:15 comment added kaya3 The examples in the question are meant to illustrate the situations at runtime where short-circuiting could happen. The idea is x <= y would short-circuit if x evaluates to INT_MIN. Not just for INT_MIN <= y where the left-side is a compile-time constant.
Oct 1, 2023 at 7:57 history answered Steve CC BY-SA 4.0