"..." 是什么意思? c中的函数声明是什么意思?
我正在查看 MinGW 附带的 stdio.h 头文件,注意到 printf 函数是这样声明的:
int printf (const char *__format, ...)
{
//body omitted
}
我以前从未在函数参数列表中见过省略号,所以我尝试了一下。它编译并运行没有错误。那么,“……”的目的是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这意味着该函数是一个可变参数函数,它采用可变数量的参数:
http://en.wikipedia.org/wiki/Variadic_function
printf()
本身可能是可变参数函数的最佳示例。That means that the function is a variadic function that takes a variable number of parameters:
http://en.wikipedia.org/wiki/Variadic_function
printf()
itself is probably the best example of a variadic function.它通知编译器该函数有一个可变参数列表。该功能仅适用于 __cdecl 调用约定。它允许调用者在最后一个固定参数之后指定所需的任何参数值,因为调用者将在函数退出时清理参数。可变参数通常用于 printf 风格的函数,其中可变参数值的解释取决于固定参数值的值(例如将各个可变参数与 __format 中的每个格式说明符相匹配)范围)。
It informs the compiler that the function has a variadic list of parameters. It is a feature that only works with the
__cdecl
calling convention. It allows the caller to specify whatever parameter values it wants after the last fixed parameter, as the caller will clean up the parameters when the function exits. Variadic parameters are commonly used for printf-style functions where the interpretation of the variadic parameter values is dependant on the value of the fixed parameter values (such as matching up individual variadic parameters to each format specifier in a__format
parameter).它用于允许可变数量的参数或未指定类型的参数,如 printf() 所做的那样。允许可变数量参数的函数称为 可变参数函数
可变参数变量通过
va_start 访问
、va_list
、va_end
和va_arg
可变数量的参数 (...)
示例实现:
希望这会有所帮助。
it is used to allow a variable number of arguments or parameters of unspecified type, as
printf()
do. the function which allows variable number of argumnets is called Variadic FunctionVariadic Variables are accessed with
va_start
,va_list
,va_end
andva_arg
Variable number of Arguments (...)
Sample Implementation:
Hope this helps.