diff options
Diffstat (limited to 'include/al')
| -rw-r--r-- | include/al/macros.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/al/macros.h b/include/al/macros.h index 0f116dc..fbf3f7e 100644 --- a/include/al/macros.h +++ b/include/al/macros.h @@ -20,6 +20,19 @@ #define UNLIKELY(x) x #endif +// Keep in mind the idea of an unreachable path is not the same +// as "We should never be here". Unreachable is a compiler hint that means +// "It's logically impossible to be here". +// https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable +// https://github.com/yehuthi/c_unreachable/blob/1f672a573b2d45cf1479fbb771c17c9ee35bff6b/include/c_unreachable.h#L21C1-L43C7 +#ifndef unreachable +#if defined(__GNUC__) +#define unreachable() (__builtin_unreachable()) +#elif defined(_MSC_VER) +#define unreachable() (__assume(0)) +#endif +#endif + #if defined MIN || defined MAX || defined CLAMP || defined SWAP || defined ARRAY_SIZE || defined STR || defined XSTR || defined BOOLSTR #error "Conflicting definitions for common macros" #endif |