Force usage of ARGPAR_ASSERT() condition when NDEBUG is defined
[argpar.git] / argpar / argpar.c
index 10f6ee8d42e93a780a65ad4c5cf66347d667c42d..82b561ceaae707002f36754c55e828d35b882206 100644 (file)
@@ -5,7 +5,6 @@
  * Copyright (c) 2020-2021 Simon Marchi <simon.marchi@efficios.com>
  */
 
-#include <assert.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdio.h>
 
 #define ARGPAR_ZALLOC(_type) ARGPAR_CALLOC(_type, 1)
 
-#define ARGPAR_ASSERT(_cond) assert(_cond)
+#ifdef NDEBUG
+/*
+ * Force usage of the assertion condition to prevent unused variable warnings
+ * when `assert()` are disabled by the `NDEBUG` definition.
+ */
+# define ARGPAR_ASSERT(_cond) ((void) sizeof((void) (_cond), 0))
+#else
+# include <assert.h>
+# define ARGPAR_ASSERT(_cond) assert(_cond)
+#endif
 
 /*
  * An argpar iterator.
This page took 0.023895 seconds and 4 git commands to generate.