diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-02-20 03:10:25 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-02-20 03:10:25 +0100 |
commit | 3d92d615396d8b3f1c43ad59196e40f15a87bcc8 (patch) | |
tree | de6c34bf190b02725241af5a3a5b9b9d5a34690b /src/common | |
parent | f806f5d28593be474fc5ef864b6fcbfbe131b4d0 (diff) |
Add the assume() macro
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/macros.h | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/common/macros.h b/src/common/macros.h index 6daf08f..3735af6 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -9,19 +9,14 @@ #define streq(x, y) (!strcmp(x, y)) #define u8eq(x, y) (!u8cmp(x, y)) -#if DEBUG || !defined(unreachable) -# if DEBUG -# include "cerr.h" -# ifdef unreachable -# undef unreachable -# endif -# define unreachable() \ - diex("%s:%d: hit unreachable in %s()", __FILE__, __LINE__, __func__) -# elifdef __clang__ -# define unreachable() __builtin_unreachable() -# else -# include <stddef.h> -# endif +#if DEBUG +# include "cerr.h" +# define assume(C) \ + ((C) ? (void)0 \ + : diex("%s:%d: %s(): assumption ā%sā failed", __FILE__, __LINE__, \ + __func__, #C)) +#else +# define assume(C) ((C) ? (void)0 : unreachable()) #endif #endif /* !AHOY_COMMON_MACROS_H */ |