The ellipsis within a function declaration means that it will accept a number of arguments otherwise, variable parameters that are unknown at run-time, which by using the standard header file stdarg.h
, the respective functions in that header file 'stdarg.h' can determine what each of the variable parameters are that makes up the argument passing into a function.
Consider this code example:
#define PANIC_BUF_LEN 256
void panic(const char *fmt, ...){
char buf[PANIC_BUF_LEN];
va_list argptr;
va_start(argptr, fmt);
vsprintf(buf, fmt, argptr);
va_end(argptr);
fprintf(stderr, buf);
exit(errcode);
}
Typical invocation can be one of example:
panic("Error: %s failed! Due to unknown error, message is '%s'\n", "my_function", "Disk not ready");
Will produce an output on console in this manner:
Error: my_function failed! Due to unknown error, message is 'Disk not ready'
Notice the usage of how the functions va_start(...)
, va_end(...)
and not to mention vsprintf(...)
will take care of filling in the blanks within the "unknown" parameters provided va_list
is initialized to point to the variable parameters which are unknown at run-time.
Edit: Just to emphasize, the invocation assumes that the string parameter in the form of a C string format is less than the maximum size represented by PANIC_BUF_LEN
in the above example, nit-picky aside, that is to illustrate how a function can take in a number of standard C formatting strings used, for example, one can specify %d
in the string format, and expect a int
to match up the parameter.