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#include <stdlib.h>
5
6#ifndef PANIC
7#include <stdio.h> // NOLINT(misc-include-cleaner) (for default panic implementation)
8#define PANIC(...) \
9 do { \
10 fprintf(stderr, __VA_ARGS__); \
11 abort(); \
12 } while (0);
13#endif
14
15#ifndef ASSERT
16#define ASSERT(expr, ...) \
17 if (!(expr)) { \
18 PANIC("assertion " #expr " failed: " __VA_ARGS__ "\n"); \
19 }
20#endif
21
22#ifndef NDEBUG
23#define DEBUG_ASSERT(expr) ASSERT(expr)
24#else
25#define DEBUG_ASSERT(expr)
26#endif