diff options
Diffstat (limited to 'cassert/include')
-rw-r--r-- | cassert/include/cassert.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cassert/include/cassert.h b/cassert/include/cassert.h new file mode 100644 index 0000000..3349b55 --- /dev/null +++ b/cassert/include/cassert.h | |||
@@ -0,0 +1,29 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <assert.h> // For convenience, bring in soft assertions with assert(). | ||
4 | #include <signal.h> | ||
5 | |||
6 | // Allow the client to define their own LOGE() macro. | ||
7 | #ifndef LOGE | ||
8 | #include <stdio.h> | ||
9 | #define LOGE(...) \ | ||
10 | { \ | ||
11 | fprintf(stderr, "[ASSERT] %s:%d: ", __FILE__, __LINE__); \ | ||
12 | fprintf(stderr, __VA_ARGS__); \ | ||
13 | fprintf(stderr, "\n"); \ | ||
14 | } | ||
15 | #endif // LOGE | ||
16 | |||
17 | #define TRAP() raise(SIGTRAP) | ||
18 | |||
19 | /// Unconditional hard assert. | ||
20 | #define FAIL(message) \ | ||
21 | LOGE(message); \ | ||
22 | TRAP(); | ||
23 | |||
24 | /// Conditional hard assert. | ||
25 | #define ASSERT(condition) \ | ||
26 | if (!condition) { \ | ||
27 | LOGE("Assertion failed: " #condition) \ | ||
28 | TRAP(); \ | ||
29 | } | ||