From 5acd6714620be6f524c565eb9d7131954a9d2a46 Mon Sep 17 00:00:00 2001 From: Lukas Wurzinger Date: Mon, 31 Oct 2022 16:48:59 +0100 Subject: [PATCH] make debug assertions opt-in --- readarg.h | 14 ++++++++++++-- test/test.c | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/readarg.h b/readarg.h index 49478c1..77eace8 100644 --- a/readarg.h +++ b/readarg.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #define READARG_STRINGS(...) ((char *[]){__VA_ARGS__, NULL}) @@ -91,6 +91,11 @@ size_t readarg_select_lower(struct readarg_bounds bounds); #ifdef READARG_IMPLEMENTATION +#ifdef READARG_DEBUG +#pragma push_macro("NDEBUG") +#undef NDEBUG +#endif + #include #include @@ -393,7 +398,8 @@ static void readarg_assign_opers(struct readarg_parser *rp) size_t req; } rest = { count - nlower, - nlower}; + nlower, + }; for (size_t i = 0; readarg_validate_arg(rp->opers + i); i++) { @@ -530,4 +536,8 @@ size_t readarg_select_lower(struct readarg_bounds bounds) : bounds.val[1]; } +#ifdef READARG_DEBUG +#pragma pop_macro("NDEBUG") +#endif + #endif diff --git a/test/test.c b/test/test.c index 1178021..a8ad4a1 100644 --- a/test/test.c +++ b/test/test.c @@ -1,7 +1,10 @@ #define READARG_IMPLEMENTATION +#define READARG_DEBUG #include "../readarg.h" +#include + int main(int argc, char **argv) { struct readarg_opt opts[] = {