Timeline for Why do relational comparison operators never short-circuit?
Current License: CC BY-SA 4.0
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 1, 2023 at 22:41 | history | edited | Davislor | CC BY-SA 4.0 | added 333 characters in body |
| Oct 1, 2023 at 21:36 | comment | added | Davislor | @kaya3 An optimizer would optimize either 0 <= returnsUnsigned() or returnsUnsigned() >= 0 the same. However, if you’re imagining short-circuiting that works exactly like && and ||, flip the operands. | |
| Oct 1, 2023 at 18:01 | comment | added | kaya3 | The example with printf doesn't seem related to short-circuiting, since with short-circuiting semantics it is only the right-hand-side which is conditionally evaluated; the left side will still always be evaluated. Your point would apply equally to a statement like printf("hello, world!"); where the compiler would be just as wrong to say "this expression's result isn't used, so it doesn't need to be evaluated". | |
| Oct 1, 2023 at 17:53 | history | edited | Davislor | CC BY-SA 4.0 | added 245 characters in body |
| Oct 1, 2023 at 17:46 | history | answered | Davislor | CC BY-SA 4.0 |