-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert.h
More file actions
50 lines (41 loc) · 3.57 KB
/
assert.h
File metadata and controls
50 lines (41 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#ifndef NDEBUG
#include <stdio.h>
#define tlbt_assert(cond) \
do { \
if (!(cond)) { \
fprintf(stderr, "Assertion failed:\nFile: '%s:%d'\nFunction: '%s'\nCondition: '%s'\n", __FILE__, __LINE__, \
__FUNCTION__, #cond); \
abort(); \
} \
} while (0)
#define tlbt_assert_msg(cond, message) \
do { \
if (!(cond)) { \
fprintf(stderr, "Assertion failed: '%s'\nFile: '%s:%d'\nFunction: '%s'\nCondition: '%s'\n", message, __FILE__, \
__LINE__, __FUNCTION__, #cond); \
abort(); \
} \
} while (0)
#define tlbt_assert_fmt(cond, message, ...) \
do { \
if (!(cond)) { \
char buffer[4096] = {0}; \
snprintf(buffer, sizeof(buffer), message, __VA_ARGS__); \
fprintf(stderr, "Assertion failed: '%s'\nFile: '%s:%d'\nFunction: '%s'\nCondition: '%s'\n", buffer, __FILE__, \
__LINE__, __FUNCTION__, #cond); \
abort(); \
} \
} while (0)
#define tlbt_assert_unreachable() \
do { \
fprintf(stderr, "Assertion failed: 'should never reach'\nFile: '%s:%d'\nFunction: '%s'\n", __FILE__, __LINE__, \
__FUNCTION__); \
abort(); \
} while (0)
#else
#define tlbt_assert(cond)
#define tlbt_assert_msg(cond, message)
#define tlbt_assert_fmt(cond, message, ...)
#define tlbt_assert_unreachable()
#endif