Using ... in function parameters

Hello!
Some functions, such as printf() can accept an infinite number of parameters. I looked at the source code, and the part that accepts an infinite number of parameters start with ... in printf()'s parameters.

printf()'s definition:
1
2
3
4
5
6
7
8
9
__mingw_stdio_redirect__
int printf (const char *__format, ...)
{
  register int __retval;
  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
  __retval = __mingw_vprintf( __format, __local_argv );
  __builtin_va_end( __local_argv );
  return __retval;
}


How would I used that in any function to accept any number of parameters of any type, and process that? To use the parameters, I would need to know how many parameters there are. How do I know that? Help is greatly appreciated.
Thanks!
http://msdn.microsoft.com/en-us/library/fxhdxye9%28v=vs.80%29.aspx


I found this by google "C++ variable arguments in function example"


Google is your best friend - and wiki :D
Unfortunately va_arg, va_list, etc. only work with simple POD types. In C++11 you can use std::initializer_list or variadic templates to pass a variable number of arguments in a more type safe way.
Topic archived. No new replies allowed.