Yes, ellipses specify a variadic function (variable length argument list). You can use the va_start
, va_arg
, and va_end
macros to "pull" arguments out. You'll need an initial argument however; they need a starting place to begin grabbing arguments off of the stack (the arg
before the ellipses + sizeof(arg)
).
/* sum a bunch of ints */
int sum(int arg_cnt, ...) {
va_list ap;
va_start(ap, arg_cnt);
int sum = 0;
for(int i = 0; i < arg_cnt; ++i) {
sum += va_arg(ap, int);
}
va_end(ap);
return sum;
}