From: Willy Tarreau Date: Thu, 28 Nov 2024 14:11:46 +0000 (+0100) Subject: MINOR: tools: add a new macro DEFVAL() to provide a default argument X-Git-Tag: v3.2-dev1~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6322c9fbbfa5f51a8e3c1dd5be7bfde2953c86fd;p=thirdparty%2Fhaproxy.git MINOR: tools: add a new macro DEFVAL() to provide a default argument This is like DEFZERO and DEFNULL, but this one allows to specify the default value to be used as the first argument. --- diff --git a/include/haproxy/tools-t.h b/include/haproxy/tools-t.h index 34e2fd818f..ef3e136a4f 100644 --- a/include/haproxy/tools-t.h +++ b/include/haproxy/tools-t.h @@ -47,15 +47,20 @@ /* return the largest possible integer of type , with all bits set */ #define MAX_RANGE(ret) (~(typeof(ret))0) +/* DEFVAL() returns either the second argument as-is, or if absent. This + * is for use in macros arguments. + */ +#define DEFVAL(_def,...) _FIRST_ARG(NULL, ##__VA_ARGS__, (_def)) + /* 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 DEFNULL(...) DEFVAL(NULL, ##__VA_ARGS__) /* DEFZERO() returns either the argument as-is, or 0 if absent. This is for * use in macros arguments. */ -#define DEFZERO(...) _FIRST_ARG(NULL, ##__VA_ARGS__, 0) +#define DEFZERO(...) DEFVAL(0, ##__VA_ARGS__) #define _FIRST_ARG(a, b, ...) b