#pragma once #include #include #define ASSERT(_cond, ...) do { \ if (!(_cond)) { \ fprintf(stderr, "%s:%d: assertion failed:\n", \ __FILE__, __LINE__); \ fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, "\n"); \ exit(1); \ } \ } while (0) #define ASSERT_NON_NULL(_ptr, _who) \ ASSERT((_ptr) != NULL, "`" _who "' should not be null") #define UNIMPLEMENTED() \ ASSERT(0, "not implemented") #define IMPOSSIBLE_(what) \ ASSERT(0, "unreachable: %s", what) // hard to explain why this is necessary ... #define IMPOSSIBLE(x) IMPOSSIBLE_(x)