From 32c24552e478f31192dc63975573bf2b6ea18267 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 19 Aug 2019 17:39:33 +0200 Subject: [PATCH] MINOR: tools: add a DEFNULL() macro to use NULL for empty args It's sometimes convenient for debugging macros not to be forced to explicitly pass NULL in an unused argument. This macro does this, it replaces a missing arg with NULL. --- include/common/standard.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/common/standard.h b/include/common/standard.h index cdefc9f5b3..ffebac8ee7 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -61,6 +61,12 @@ * power of 2, and 0 otherwise */ #define POWEROF2(x) (((x) & ((x)-1)) == 0) +/* DEFNULL() returns either the argument as-is, or NULL if absent. This is for + * use in macros arguments. + */ +#define DEFNULL(...) _FIRST_ARG(NULL, ##__VA_ARGS__, NULL) +#define _FIRST_ARG(a, b, ...) b + /* operators to compare values. They're ordered that way so that the lowest bit * serves as a negation for the test and contains all tests that are not equal. */ -- 2.47.3