You are viewing a single comment's thread. Return to all comments →
int var_accum(int (*f) (int, int), int count, ...) { va_list args; va_start(args, count); int retval = 0; while(count--) retval = f(retval, va_arg(args, int)); va_end(args); return retval; } int sum(int r, int n) { return r + n; } int min(int r, int n) { return r < n ? r : n; } int max(int r, int n) { return r > n ? r : n; } #define sum(c, ...) var_accum(&sum, c, __VA_ARGS__); #define min(c, ...) var_accum(&min, c, __VA_ARGS__); #define max(c, ...) var_accum(&max, c, __VA_ARGS__);
Seems like cookies are disabled on this browser, please enable them to open this website
Variadic functions in C
You are viewing a single comment's thread. Return to all comments →