#ifndef VLIBC_ASSERT_H #define VLIBC_ASSERT_H /* * vlibc — . * * The assert diagnostic macro. When NDEBUG is defined the macro expands to * ((void)0) and the expression is not evaluated; otherwise a false result * calls the library-internal __vlibc_assert_fail(), which writes the * diagnostic to fd 2 through the raw syscall layer and terminates the * process with __builtin_trap(). The helper deliberately does not depend on * abort(), exit() or stdio: those land in later todos, and an assertion * failure must work even when the runtime is half-initialized. * * static_assert is a C23 keyword; for C17 and older this header maps it onto * _Static_assert, and _Static_assert itself remains usable in every mode. * * This header is ISO C core and is present in every profile. */ #include /* NDEBUG: strip the check entirely, matching the standard. */ #ifdef NDEBUG #define assert(expr) ((void)0) #else /* * Terminate after writing the failing assertion to fd 2; never returns. * Implemented in src/internal/assert_fail.c. The name sits in the * implementation-reserved namespace because it is libc plumbing, not * public API. */ __attribute__((noreturn)) void __vlibc_assert_fail(const char *expr, const char *file, int line, // NOLINT(bugprone-reserved-identifier) const char *func); #define assert(expr) ((expr) ? (void)0 : __vlibc_assert_fail(#expr, __FILE__, __LINE__, __func__)) #endif #if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L) #define static_assert _Static_assert #endif #endif /* VLIBC_ASSERT_H */