Often I see a function declared like this:
void Feeder(char *buff, ...)
what does "..." mean?
Often I see a function declared like this:
void Feeder(char *buff, ...)
what does "..." mean?
it allows a variable number of arguments of unspecified type (like printf
does).
you have to access them with va_start
, va_arg
and va_end
see http://publications.gbdirect.co.uk/c_book/chapter9/stdarg.html for more information
It means that a variadic function is being declared.
Variadic functions are functions which may take a variable number of arguments and are declared with an ellipsis in place of the last parameter. An example of such a function is
printf
.A typical declaration is
int check(int a, double b, ...);
Variadic functions must have at least one named parameter, so, for instance,
char *wrong(...);
is not allowed in C.
The three dots '...' are called an ellipsis. Using them in a function makes that function a variadic function. To use them in a function declaration means that the function will accept an arbitrary number of parameters after the ones already defined.
For example:
Feeder("abc");
Feeder("abc", "def");
are all valid function calls, however the following wouldn't be:
Feeder();
variadic function (multiple parameters)
#include <stdarg.h>
double average(int count, ...)
{
va_list ap;
int j;
double tot = 0;
va_start(ap, count); //Requires the last fixed parameter (to get the address)
for(j=0; j<count; j++)
tot+=va_arg(ap, double); //Requires the type to cast to. Increments ap to the next argument.
va_end(ap);
return tot/count;
}