diff options
Diffstat (limited to 'include/macros.h')
-rw-r--r-- | include/macros.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/macros.h b/include/macros.h new file mode 100644 index 0000000..2b62625 --- /dev/null +++ b/include/macros.h @@ -0,0 +1,22 @@ +#ifndef MLIB_MACROS_H +#define MLIB_MACROS_H + +#define MIN(x, y) ((x) < (y) ? (x) : (y)) +#define MAX(x, y) ((x) > (y) ? (x) : (y)) + +#define lengthof(a) (sizeof(a) / sizeof(*(a))) + +#define memeq(x, y, n) (!memcmp(x, y, n)) +#define streq(x, y) (!strcmp(x, y)) +#define u8eq(x, y) (!u8cmp(x, y)) + +#ifdef NDEBUG +# include <stddef.h> +# define ASSUME(p) ((p) ? (void)0 : unreachable()) +#else +# include "errors.h" +# define ASSUME(p) ((p) ? (void)0 : warnx("%s:%s:%d: assumption ā%sā failed", \ + __FILE__, __func__, __LINE__, #p)) +#endif + +#endif /* !MLIB_MACROS_H */ |