From: Willy Tarreau Date: Mon, 19 Aug 2019 15:39:33 +0000 (+0200) Subject: MINOR: tools: add a DEFNULL() macro to use NULL for empty args X-Git-Tag: v2.1-dev2~198 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=32c24552e478f31192dc63975573bf2b6ea18267;p=thirdparty%2Fhaproxy.git 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. --- 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. */