What's the correct term for the '…' token?

∥☆過路亽.° 提交于 2019-12-08 14:50:57

问题


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


回答1:


Variable length parameter list

Edit:

Or, if describing the function itself: Variadic function




回答2:


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




回答3:


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




回答4:


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




回答5:


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.




回答6:


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




回答7:


Variadic




回答8:


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


来源:https://stackoverflow.com/questions/4937454/whats-the-correct-term-for-the-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!