Possible Duplicate:
What's does … mean in an argument list in C ?
function fun1(...)
{
}
Please tell me about what is the use and how to use ellipsis operator in c. Thanks,
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.
va_list is a complete object type suitable for holding the information needed by the macros va_start, va_copy, va_arg, and va_end. If a va_list instance is created, passed to another function, and used via va_arg in that function, then any subsequent use in the calling function should be preceded by a call to va_end.
Variadic functions are functions that can take a variable number of arguments. In C programming, a variadic function adds flexibility to the program. It takes one fixed argument and then any number of arguments can be passed.
It takes two parameters: the va_list and the last specified non-ellipsis parameter. To get each ellipsis parameter, the va_arg macro requires the va_list object ( list ) and the type of the last non-ellipsis parameter. Our code example contains only one specified parameter, num of type int.
An ellipsis is used to represent a variable number of parameters to a function. For example:
void format(const char* fmt, ...)
The above function in C could then be called with different types and numbers of parameters such as:
format("%d-%d-%d", 2010, 9, 25);
and
format("product: %s, price: %f", "HDD", 450.90);
C99 introduced Variadic macros which also makes use of ellipsis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With