12 points signa11 3 hours ago 10 comments
johnea 1 hour ago | parent
stop50 1 hour ago | parent
tyushk 1 hour ago | parent
[1] https://doc.rust-lang.org/std/macro.unreachable.html [2] https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked....
mpyne 1 hour ago | parent
Though, it would be better if programmers read deliberate instances of UB as if they literally said "std::unreachable()" at that point in the code, as that would better convey how the optimizer passes will see things after dozens of frontend and middle-end passes have run before it.
torstenvl 48 minutes ago | parent
Except that isn't true.
There are basically two kinds of undefined behavior.
The first is undefinable behavior, the kind that easily goes disastrously wrong, like writing to random memory locations.
The second is incidentally undefined behavior, something where there just isn't enough implementation consensus for the standard to settle on it, like realloc(p, 0).
There's no standard terminology I'm aware of to distinguish the two. But the distinction exists.
And where programmers read deliberate instances of UB, it's usually the latter, e.g., writing directly to an address memory mapped to device I/O in that particular environment.
NobodyNada 21 minutes ago | parent
There is: implementation-defined behavior. Your example of writing to an MMIO address is such an example, as the standard says casting an int to a pointer is implementation-defined. (However, the C standard has plenty of cases of undefined behavior that probably should have been implementation-defined.)
pestatije 1 hour ago | parent
charleslmunger 1 hour ago | parent
omoikane 57 minutes ago | parent
Another alternative is to use `__builtin_unreachable()` (not standard, but available in GCC and Clang).
zarakshR 39 minutes ago | parent