2022-06-20 06:28:03 +00:00
|
|
|
|
2022-06-02 23:41:48 +00:00
|
|
|
#pragma once
|
2022-06-11 20:21:57 +00:00
|
|
|
|
2022-08-05 04:00:54 +00:00
|
|
|
#if defined(_MSC_VER) && !defined(__clang__)
|
2022-07-31 09:11:28 +00:00
|
|
|
#define _Noreturn
|
|
|
|
#endif
|
|
|
|
|
2022-08-05 06:27:46 +00:00
|
|
|
void _assert(
|
2022-06-16 12:36:35 +00:00
|
|
|
char const *cond,
|
2022-06-06 10:49:19 +00:00
|
|
|
char const *func,
|
|
|
|
char const *file,
|
2022-06-16 12:36:35 +00:00
|
|
|
int line
|
2022-06-06 10:49:19 +00:00
|
|
|
);
|
2022-06-02 05:18:26 +00:00
|
|
|
|
|
|
|
#if defined(NDEBUG)
|
|
|
|
#define assert(ignore) ((void)0)
|
2022-07-30 02:06:35 +00:00
|
|
|
#elif defined(DEBUG)
|
|
|
|
#if __GNUC__
|
|
|
|
#define assert(c) if (!(c)) __builtin_trap()
|
|
|
|
#elif _MSC_VER
|
|
|
|
#define assert(c) if (!(c)) __debugbreak()
|
2022-08-04 09:47:38 +00:00
|
|
|
// TODO: Handle Cuik, and if such handling is not required remove this comment
|
2022-07-30 02:06:35 +00:00
|
|
|
#else
|
|
|
|
// In debug mode there shouldn't be any optimizations so this should
|
|
|
|
// work as a simple way to cause a trap.
|
|
|
|
#define assert(c) if (!(c)) *(volatile int *)0 = 0
|
|
|
|
#endif
|
2022-06-02 05:18:26 +00:00
|
|
|
#else
|
|
|
|
#define _static_assert _Static_assert
|
|
|
|
#define assert(condition) \
|
|
|
|
do { \
|
|
|
|
if(!(condition)) { \
|
2022-06-16 12:36:35 +00:00
|
|
|
_assert(#condition, __func__, __FILE__, __LINE__); \
|
2022-06-02 05:18:26 +00:00
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
#endif
|