|
P99
|
Helper macro to declare a variable length parameter list. Wrap your function into a macro that uses P99_LENGTH_ARR_ARG. If used through that macro, the correct value for unsigned P99_FSYMB(tutu)(unsigned a, size_t number, unsigned const*arr); #define tutu(A, ...) P99_FSYMB(tutu)(A, P99_LENGTH_ARR_ARG(unsigned const, __VA_ARGS__)) In the definition of the function you then may use an array of the arguments in the obvious way. unsigned P99_FSYMB(tutu)(unsigned a, size_t number, unsigned const*arr) { unsigned ret = 0; for (size_t i = 0; i < number; ++i) { ret += arr[i]; } return ret % a; } In this toy example unsigned magic = tutu(3, 1, 3, 5, 7);
which will result in converting 1, 3, 5, 7 (the variable arguments) to In the example This method here is generally more efficient than using P99_VA_ARGS since it results in code that can easier be inlined by the compiler. In particular, if a function as
Definition at line 272 of file p99_args.h. |
1.7.6.1