Derive-C
Loading...
Searching...
No Matches
panic.h
Go to the documentation of this file.
1// JUSTIFY: No guards, just for each macro
2// - allows overriding panic, differently for each template instantiation
3#include <assert.h>
4
5#if !defined PANIC
6 #include <stdio.h> // NOLINT(misc-include-cleaner) (for default panic implementation)
7 #define PANIC(...) \
8 do { \
9 fprintf(stderr, __VA_ARGS__); \
10 abort(); \
11 } while (0);
12#endif
13
14#if !defined ASSERT
15 #define ASSERT(expr, ...) \
16 if (!(expr)) { \
17 PANIC("assertion " #expr " failed: " __VA_ARGS__ "\n"); \
18 }
19#endif
20
21#if !defined UNREACHABLE
22 #define UNREACHABLE(...) PANIC("unreachable: " __VA_ARGS__ "\n");
23#endif
24
25#if !defined DEBUG_UNREACHABLE
26 #if !defined NDEBUG
27 #define DEBUG_UNREACHABLE(...) UNREACHABLE(__VA_ARGS__)
28 #else
29 #define DEBUG_UNREACHABLE(...) __builtin_unreachable()
30 #endif
31#endif
32
33#if !defined NDEBUG
34 #define DEBUG_ASSERT(expr) ASSERT(expr)
35#else
36 #define DEBUG_ASSERT(expr)
37#endif