Reputation: 25571
Consider printf:
int printf ( const char * format, ... );
What are the terms used to describe the ...
and the functions that use it? I've been calling it an ellipsis, but that's like calling &
the "ampersand operator."
Upvotes: 14
Views: 3063
Reputation: 12218
Martin and Demian are both right:
Upvotes: 1
Reputation: 9224
In addition to "ellipsis" and "variadic function", one also sees the terms "vararg" and "varargs" thrown around. This appears to be an abbreviation for "variable argument list", judging by the language surrounding the (LEGACY) header <varargs.h>
in POSIX.
Also, the principle reason that the term "ampersand operator" is not used is that the ampersand can represent either of two different operators, depending on the context, which would make the term ambiguous. This does not occur with the ellipsis; there is no other meaning assigned to it, so using the term "ellipsis" for the token "...
" is not like using the term "ampersand operator" for the token "&
".
Upvotes: 2
Reputation: 2193
This C++ draft specification refers to it simply as 'ellipsis' and sometimes with a definite or indefinite article, as 'an ellipsis' or 'the ellipsis'.
5.2.2 "Function call" section 6 contains:
A function can be declared to accept fewer arguments (by declaring default arguments (8.3.6)) or more arguments (by using the ellipsis, ... 8.3.5) than the number of parameters in the function definition (8.4).
8.3.5 "Functions" section 2 contains:
If the parameter-declaration-clause terminates with an ellipsis, the number of arguments shall be equal to or greater than the number of parameters that do not have a default argument.
8.3.6 section 4 contains sample code:
void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
// a parameter with a default argument
Extra pedantry: section 13.3.3.1.3 ("Ellipsis conversion sequences") refers to "the ellipsis parameter specification". However, as stated in the sample code above, the ellipsis is not, strictly speaking, a parameter. 8.3.5 section 1 explains that, while the ellipsis appears in the parameter-declaration-clause, it follows the parameter-declaration-list.
Upvotes: 2
Reputation: 72301
"Ellipsis" is in fact often the best term here. Sometimes we refer to "arguments passed using the ellipsis" (C++03 8.3.5p2). In the context of figuring out the best overloaded function, an argument can be said to "match the ellipsis" (C++03 13.3.2p2).
printf
and other functions like it are often called "variadic functions".
Note: The coming C++0x Standard offers two different ways of declaring and implementing variadic functions (the va_arg
way and the template way). But both involve the ellipsis token.
Upvotes: 8
Reputation: 21368
Variable length parameter list
Edit:
Or, if describing the function itself: Variadic function
Upvotes: 18
Reputation: 96109
Ellipsis operator is the only term I have heard - it's rare enough (thankfully) that you don't need anything else!
Upvotes: 4