mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-27 05:18:00 +00:00
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.
This commit is contained in:
parent
295071007b
commit
6322c9fbbf
@ -47,15 +47,20 @@
|
|||||||
/* return the largest possible integer of type <ret>, with all bits set */
|
/* return the largest possible integer of type <ret>, with all bits set */
|
||||||
#define MAX_RANGE(ret) (~(typeof(ret))0)
|
#define MAX_RANGE(ret) (~(typeof(ret))0)
|
||||||
|
|
||||||
|
/* DEFVAL() returns either the second argument as-is, or <def> 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
|
/* DEFNULL() returns either the argument as-is, or NULL if absent. This is for
|
||||||
* use in macros arguments.
|
* 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
|
/* DEFZERO() returns either the argument as-is, or 0 if absent. This is for
|
||||||
* use in macros arguments.
|
* use in macros arguments.
|
||||||
*/
|
*/
|
||||||
#define DEFZERO(...) _FIRST_ARG(NULL, ##__VA_ARGS__, 0)
|
#define DEFZERO(...) DEFVAL(0, ##__VA_ARGS__)
|
||||||
|
|
||||||
#define _FIRST_ARG(a, b, ...) b
|
#define _FIRST_ARG(a, b, ...) b
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user