va_pp.h🔗
#include <va_pp.h>
Defines
-
VA_DO_STRINGIZE
(arg)🔗
-
VA_STRINGIZE
(arg)🔗 Converts the argument to a string.
const char* name = VA_STRINGIZE(ClassName); // const char* name == "ClassName";
-
VA_DO_JOIN
(a, b)🔗
-
VA_JOIN
(a, b)🔗 Joins arguments a and b.
struct VA_JOIN(Class, Name); // struct ClassName.
-
VA_DO_JOIN3
(a, b, c)🔗
-
VA_DO_JOIN4
(a, b, c, d)🔗
-
VA_DO_JOIN5
(a, b, c, d, e)🔗
-
VA_COMMA
()🔗 Expands to a comma (,).
-
VA_LPAREN
()🔗 Expands to a left parenthesis.
-
VA_RPAREN
()🔗 Expands to a right parenthesis.
-
VA_EXPAND
(PARAM)🔗 Expands to PARAM.
This macro is useful if you need to format the arguments of a macro using another macro.
#define PRINTF(FORMAT, ARG1, ARG2) printf(FORMAT, ARG1, ARG2); #define ARGS1 "%s%d", "abc" #define ARGS2 1 #define CALL(MACRO) VA_EXPAND(MACRO VA_LPAREN() ARGS1 VA_COMMA() ARGS2 VA_RPAREN()) CALL(PRINTF); // expands to // printf ("%s%d", "abc", 1);
-
VA_REMOVE_PARENS
(N, PARAMS)🔗 Remove parentheses around PARAMS.
The number of comma-separated elements in PARAMS must be N.
VA_REMOVE_PARENS(3, (a, b, c)) // Expands to a, b, c
-
VA_FOR_N
(MACRO, N, ELEMENTS)🔗 Repeats MACRO for each of the N elements in ELEMENTS.
MACRO will be called with two parameters: the (zero-based) index of the current element and the element.
#define PRINTF(N, X) printf(#X); VA_FOR_N(PRINTF, 3, (a, b, c)) // Expands to // printf("a"); printf("b"); printf("c");
-
VA_FOR_N_ARG
(MACRO, ARG, N, ELEMENTS)🔗 Same as [VA_FOR_N], but passes ARG(N) as the first parameter to MACRO instead of N.
#define MYMACRO(A, B) A B; VA_FOR_N_ARG(MYMACRO, int VA_NULL, 3, (a, b, c)); // Expands to // int a; int b; int c;
-
VA_FOR_N_SEP
(MACRO, SEPARATOR, N, ELEMENTS)🔗 Repeats MACRO for each of the N elements in ELEMENTS, placing SEPARATOR(N) between each element.
SEPARATOR will be called with one parameter: the (zero-based) index of the current element and the element itself. Use
VA_COMMA_SEP
to place a comma between elements.#define MYMACRO(N, X) i##X = N int VA_FOR_N_SEP(MYMACRO, VA_COMMA_SEP, 3, (a, b, c)); // Expands to // int ia = 0 , ib = 1 , ic = 2;
-
VA_FOR_N_SEP_ARG
(MACRO, SEPARATOR, ARG, N, ELEMENTS)🔗 Same as [VA_FOR_N_SEP], but passes ARG(N) as the first parameter to MACRO instead of N.
-
VA_REPEAT_N
(MACRO, N)🔗 Repeats MACRO N times.
The expanded result is
MACRO(0) MACRO(1) ... MACRO(N-1)
.
-
VA_NULL
(N)🔗
-
VA_COMMA_SEP
(N)🔗
-
VA_1ST_ARG
(_1, ...)🔗
-
VA_REST_ARGS
(_1, ...)🔗
-
VA_2ND_ARG
(_1, _2, ...)🔗
-
VA_3RD_ARG
(_1, _2, _3, ...)🔗
-
VA_INDIRECT
(MACRO, ARGS)🔗
-
VA_EVAL
(...)🔗 Evaluates up to 243 levels of deferred macros.
Since the C preprocessor cannot evaluate macros recursively, one must instead defer the evaluation of a recursive macro call and then force another pass using this macro.
#define A() 123 A() // 123 VA_DEFER(A)() // A() VA_EVAL(VA_DEFER(A)()) // 123
-
VA_EVAL1
(...)🔗
-
VA_EVAL2
(...)🔗
-
VA_EVAL3
(...)🔗
-
VA_EVAL4
(...)🔗
-
VA_EVAL5
(...)🔗
-
VA_EMPTY
()🔗
-
VA_DEFER
(X)🔗 Defers the expansion of X.
Can be used with VA_EVAL to implement recursive macros.
-
VA_ARGS_EXPAND
(X)🔗
-
VA_NARGS
(...)🔗 Expands to the number of variable arguments.
The maximum allowed number of arguments is 64.
VA_NARGS(1) // 1 VA_NARGS(a, b) // 2
-
VA_DO_NARGS
(...)🔗
-
VA_ARGS_N
(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, N, ...)🔗
-
VA_RSEQ_64
()🔗
-
VA_FOR
(MACRO, ELEMENTS)🔗 For loop macros for C preprocessors that support variadic macros.
-
VA_FOR_SEP
(MACRO, SEPARATOR, ELEMENTS)🔗
-
VA_FOR_ARG
(MACRO, ARG, ELEMENTS)🔗
-
VA_FOR_SEP_ARG
(MACRO, SEPARATOR, ARG, ELEMENTS)🔗