1

I answered this question How can I get my va_list arguments to repeat itself? and noticed the uncommon function declaration:

void ordered(int num1, double list ...);

First i thought the compiler would complain but clang 3.2 didn't and neither did g++ 4.7.2.

What does this declaration expand to? As what does it get interpreted?

Edit: I know about the ellipsis. But the normal form is <return type> <function-name>(<argument1-type> <arg-name>, ...); in the example the comma is missing.

Community
  • 1
  • 1
RedX
  • 14,749
  • 1
  • 53
  • 76
  • This kind of reminds me of http://stackoverflow.com/questions/5625600/what-is-the-meaning-of-token – chris Mar 27 '13 at 13:57

5 Answers5

3

It's the same as:

void ordered(int num1, double list, ...);
chris
  • 60,560
  • 13
  • 143
  • 205
3

This is a snippet of the grammar in the C++ standard:

parameter-declaration-clause:
  parameter-declaration-list[opt] ...[opt]
  parameter-declaration-list , ...

Basically the ellipsis can be preceded by , if the are other parameter declarations, but it need not be. The function declaration:

void f(int,double...);

really means:

void f(int,double,...);
David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
2
void ordered(int num1, double list ...);

is same as:

void ordered(int num1, double list, ...);

Reference:
Standard C++11 8.3.5.3/4:

parameter-declaration-clause:
parameter-declaration-listopt ...opt
parameter-declaration-list , ...

If the parameter-declaration-clause terminates with an ellipsis or a function parameter pack (14.5.3), the number of arguments shall be equal to or greater than the number of parameters that do not have a default argument and are not function parameter packs. Where syntactically correct and where “...” is not part of an abstract-declarator, “, ...” is synonymous with “...”.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
1

The three dots (...) are called "ellipses" and denote a variable argument list. So you can pass as many arguments as you like (there is an OS-specified limitation, though). In this way, printf works, for example.

See here for further explanation.

bash.d
  • 13,029
  • 3
  • 29
  • 42
1

I guess you mean the "..." right?

For some functions it is not possible to specify the number and type of all arguments expected in a call. Such a function is declared by terminating the list of argument declarations with the ellipsis (...).