C standard library - <stdarg.h>

Brief introduction

stdarg.h header file defines a variable of type va_listand three macros, these three macros can be used in a number of unknown parameters (ie, a variable number of arguments) acquiring function parameters.

Variable parameters in the parameter list through the end of the function is to use an ellipsis (, /en.) definition.

Library variants

Here is a variable type defined in the header file stdarg.h:

序号变量 & 描述
1va_list
这是一个适用于va_start()、va_arg()va_end()这三个宏存储信息的类型。

Macro library

The following is a macro defined in the header file stdarg.h:

序号宏 & 描述
1 void va_start(va_list ap, last_arg)
这个宏初始化ap变量,它与va_argva_end宏是一起使用的。last_arg是最后一个传递给函数的已知的固定参数,即省略号之前的参数。
2 type va_arg(va_list ap, type)
这个宏检索函数参数列表中类型为type的下一个参数。
3 void va_end(va_list ap)
这个宏允许使用了va_start宏的带有可变参数的函数返回。如果在从函数返回之前没有调用va_end,则结果为未定义。