|
|
|
|
|
by peterfirefly
1149 days ago
|
|
unreachable() is just the standardized form of __builtin_unreachable() (gcc/clang) and __assume(0) (MSVC). I often have a macro called UNREACHABLE() that evaluates to assert(0) or __builtin_unreachable() depending on NDEBUG. It improves the generated code a bit. One trick one can use is to define ASSERT() as a wrapper around assert() or something like do { if (!x) unreachable(); } while (0)
This is a really nice way to tell the compiler about invariants -- and generate better code (and better warnings!).There are no fuck ups involved. None. constexpr is great because it reduces the need for macros. There are three features that make almost all macro use unnecessary. They are enums, inline, and constexpr. Good enough inline support has only really been available for a few years -- by "good enough", I mean "doesn't slow down CPU emulator code". Things are really looking up for C, in my view. |
|