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.
This commit is contained in:
Willy Tarreau 2019-08-19 17:39:33 +02:00
parent 9bead8c7f5
commit 32c24552e4

View File

@ -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.
*/