34

One of the uses of ... is to denote variadic entities in C and C++.

  • What is its name?

  • Is it classified as an operator or something else when used that way?

  • Any other details regarding ...?

Edit: I know the purpose of .... I am asking about its name and classification, which I hope, is similar in C and C++.

Rohan Bari
  • 7,482
  • 3
  • 14
  • 34
Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
  • 1
    Does this answer your question? [In a C function declaration, what does "..." as the last parameter do?](https://stackoverflow.com/questions/2735587/in-a-c-function-declaration-what-does-as-the-last-parameter-do) – Ajay Dabas Jan 11 '20 at 17:53
  • 1
    C variadic functions and C++ variadic template arguments are completely different, can you give context in which you found it? (PS, C/C++ doesn't exist, please pick one) – JVApen Jan 11 '20 at 17:57
  • 1
    I just want to know its name and classification – Ardent Coder Jan 11 '20 at 17:58

4 Answers4

46

It is one of the punctuators.

6.4.6  Punctuators
Syntax punctuator:
     one of  [    ]    (    )    {   }    .    ->
             ++   --   &    *    +   -    ~    !
             /    %    <<   >>   <   >    <=   >=    ==   !=   ^   |   &&   ||
             ?    :    ;    ...
             =    *=   /=   %=   +=  -=   <<=  >>=   &=   ^=   |=
             ,    #    ##
             <:   :>   <%   %>   %:   %:%:

In the function declaration it is called the ellipsis.


Ellipsis is also used by some compiler C language extensions. Example - gcc switch/case range extension

const char *test(unsigned num)
{
    switch(num)
    {
        case 0 ... 9:
            return "the value is in the 0 to 9 range";
        case 10 ... 99:
            return "the value is in the 10 to 99 range";
        default:
            return "out of tested range";
    }
}

https://godbolt.org/z/YBLma-

user3840170
  • 26,597
  • 4
  • 30
  • 62
0___________
  • 60,014
  • 4
  • 34
  • 74
  • 1
    However, as one of the comments in my question mentioned about parameter packs, why didn't you mention it in your answer? – Ardent Coder Jan 11 '20 at 18:52
  • 3
    Link to the C11 Standard: http://port70.net/~nsz/c/c11/n1570.html#6.4.6 – pmg Jan 11 '20 at 18:52
  • 5
    @ArdentCoder: It's still called an ellipsis in C++, even for parameter packs. – Nicol Bolas Jan 11 '20 at 18:53
  • 4
    I would add that `...` is _not_ an operator, because it cannot form part of an _expression_ (in the sense of 'expression' defined by [C11 §6.5](http://port70.net/~nsz/c/c11/n1570.html#6.5)). It has more in common with `{` `}` and `;` than with the other punctuators. – zwol Jan 12 '20 at 16:58
  • 1
    @zwol In C++ the token `...` can be part of an expression. But it's not considered an _operator_ by the formal syntax. – aschepler Feb 01 '20 at 17:10
  • 1
    @ArdentCoder Fold expressions: https://en.cppreference.com/w/cpp/language/fold – aschepler Feb 02 '20 at 15:02
12

The ... is referred to as an ellipsis both in English and in the C standard.

Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
Ahmed Masud
  • 21,655
  • 3
  • 33
  • 58
7

One of the uses of ... is to denote variadic entities in C and C++.`

Yes, In layman's terms ... can be thought of as denoting more than one or multiples (as in pseudo-code punctuation we sometimes use multiple dots to resemble different types) of a use case, for which if we consider variadics (being multiple in the sense of 'varying' arguments/parameters) in C++, it would refer to a variable number of arguments for functions or templates.

What is its name?

Ellipsis

Is it classified as an operator or something else when used in that way?

No, it's definitely not an operator as it allows you to pass any number of arguments, not operate on them.

Any other details regarding ...?

As far as I know -

  1. Its a special specifier;
  2. The ellipsis always comes last in the argument list;
  3. As far as its usage is concerned, its only used when you want to remove the limits on the number of parameters for a template/function or when you require to have an extensible number of parameters for expansion. (i.e. it provides parameter pack expansion in a variadic class template or function template) In practice we mostly require a fixed set of known parameters, so it isn't applicable to most cases;
  4. It can be used with sizeof operator, as it's classified as a pack expansion as well.

Edit: I know the purpose of ... I am asking about its name and classification, which I hope, is similar in both C and C++.

The name is same, but usage may vary for C++ and C.

Am only familiar with its use in the former language. (I remember having a HackerRank problem on Variadics, covering its utility.)

3

The sequence of three full stops ... is called an ellipsis in both C and C++


In C++, the ellipsis helps initialize and expand different kinds of packs.
  • A parameter pack - when there is an ellipsis between the type and the identifier
    Type ... identifier

  • A pack expansion - consists of a pattern and an ellipsis
    pattern...

Andreas DM
  • 10,685
  • 6
  • 35
  • 62