4 ms·
Ego.
by Eridrus 6y ago
Ego.
- kevincox 6y agoIf you are really sure put __builtin_unreachable()
- pvarangot 6y agoI'm pretty sure he didn't have that on most of the platforms he was targeting with his portable C code, it's not even there on some of them now.
- jstimpfle 6y agowhat you do is you define a macro in a common header. Like UNREACHABLE().
- jstimpfle 6y agoShoot I have done that in the past but it seems I actually wanted __builtin_trap().
- kevincox 6y agoYeah, that footgun should really have a more explicit name. __dear_compiler_i_promise_that_this_statement_is_unreachable_and_you_may_optimize_based_on_my_good_word_upon_penalty_of_undefined_behaviour()
- derefr 6y agoI mean, what other semantics would anyone expect it to have—presuming they think for a moment about why it exists as its own thing in the first place?
- dodobirdlord 6y agoRust being Rust, the equivalent causes a safe teardown. https://doc.rust-lang.org/std/macro.unreachable.html https://doc.rust-lang.org/std/macro.unreachable.html The UB causing equivalent is of course unsafe. https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.html https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked....
- jstimpfle 6y agoOk so what's the answer if you apply the question to __builtin_trap()?
- saagarjha 6y agoEven better, just actually perform undefined behavior on that branch and the compiler will get rid of it.