Attention people who think UB is fine

signa11 12 points 10 comments October 25, 2026
blog.habets.se · View on Hacker News

Discussion Highlights (4 comments)

johnea

Isn't a solution to simply not use unreachable()?

pestatije

UB - undefined behaviour

charleslmunger

This is sort of true, except that behavior can be undefined in the standard but defined in your implementation. One of the best examples is -fwrapv, which makes signed integer overflow not UB. And Fil-C has no undefined behavior that I'm aware of. But most implementations target the standard and "define" what the standard doesn't to be "whatever I feel like, in service of implementation simplicity and performance". What matters is what your implementation guarantees, which should be a superset of what the standard does.

omoikane

The first example should have changed the heading to "C++ code" as opposed to "C code" due to the use of `std::unreachable()`. This matches the godbolt link. Another alternative is to use `__builtin_unreachable()` (not standard, but available in GCC and Clang).

Semantic search powered by Rivestack pgvector
10,486 stories · 98,859 chunks indexed