rcx

miscellaneous C library
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

debug.h (1038B)


      1 #pragma once
      2 
      3 #include <stdnoreturn.h>
      4 
      5 #include "def.h"
      6 
      7 /* REQUIRE is like assert from assert.h, but it never gets disabled and it
      8  * takes an optional message like C11's static_assert. */
      9 #define REQUIRE(cond, ...) ((void)((cond) || (r_throw( \
     10 		"Assertion failed [%s:%d]: %s\n", \
     11 		__FILE__, __LINE__, VA_DEFAULT(,##__VA_ARGS__, #cond) \
     12 	), 0)))
     13 
     14 /* ASSERT is like the libc assert except it accepts an optional message. The
     15  * name is in all caps mostly to not conflict with the libc assert (which could
     16  * be a problem if you include a library header that includes assert.h), but it
     17  * also serves as a reminder that ASSERT is a macro that might not behave as
     18  * expected; in particular, ASSERT does not evaluate its argument when NDEBUG
     19  * is set! */
     20 #ifdef NDEBUG
     21 #define ASSERT(cond, ...) ((void)0)
     22 #else
     23 #define ASSERT REQUIRE
     24 #endif
     25 
     26 #define unreachable REQUIRE(0, "unreachable code reached")
     27 
     28 /* Print the given formatted message to stderr followed by a newline,
     29  * and then abort. */
     30 noreturn void r_throw(char *fmt, ...);