14

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."

Maxpm
  • 24,113
  • 33
  • 111
  • 170
  • 14
    *Ellipsis* is the term used for `...` in the standard. It applies to `...` token specifically. Function declared with ellipsis in the parameter list is called *variadic* function. – AnT stands with Russia Feb 08 '11 at 19:52
  • 6
    The actually correct technical term is the *dot dot dot* operator. – Edward Strange Feb 08 '11 at 20:31
  • 2
    @Noah Roberts: That's surprising to hear, since it's not an operator. – caf Feb 09 '11 at 00:30
  • "that's like calling & the "ampersand operator." -- it really isn't, since "..." is actually used here as an ellipsis, whereas the ampersand symbol is used as a binary AND operator. – Jim Balter Jun 30 '12 at 02:01

8 Answers8

18

Variable length parameter list

Edit:

Or, if describing the function itself: Variadic function

Demian Brecht
  • 21,135
  • 5
  • 42
  • 46
  • Your citation makes not reference to "...". Both the C and C++ standards refer to "..." as what it is ... an ellipsis. – Jim Balter Jun 30 '12 at 02:05
14

Ellipsis notation (, ...) p202 "K+R The C Programming Language"

Andrew
  • 2,598
  • 16
  • 27
8

"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.

aschepler
  • 70,891
  • 9
  • 107
  • 161
4

Ellipsis operator is the only term I have heard - it's rare enough (thankfully) that you don't need anything else!

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • 4
    What about dotdotdot? It's fun to say :) –  Feb 08 '11 at 19:43
  • @Øystein That's what I originally looked up, since Google just ignored "...." (Yes, that is a period after an ellipsis.) – Maxpm Feb 08 '11 at 20:11
  • 1
    @Maxpm: At times like these, the British convention for quotation marks comes in handy. – SamB Feb 08 '11 at 22:40
2

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.

Jeff
  • 2,023
  • 2
  • 14
  • 10
2

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 "&".

SamB
  • 9,039
  • 5
  • 49
  • 56
1

Variadic

Daniel DiPaolo
  • 55,313
  • 14
  • 116
  • 115
1

Martin and Demian are both right:

  • The three "." together form a ellipsis (On the Macintosh this is a single special character "...", but not usable for C++)
  • In C++ an ellipsis is used to define a Variable length parameter list
Jim Balter
  • 16,163
  • 3
  • 43
  • 66
RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92