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 (, ...) definition.
Library variants
Here is a variable type defined in the header file stdarg.h:
序号 | 变量 & 描述 |
---|---|
1 | va_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_arg和va_end宏是一起使用的。last_arg是最后一个传递给函数的已知的固定参数,即省略号之前的参数。 |
2 | type va_arg(va_list ap, type) 这个宏检索函数参数列表中类型为type的下一个参数。 |
3 | void va_end(va_list ap) 这个宏允许使用了va_start宏的带有可变参数的函数返回。如果在从函数返回之前没有调用va_end,则结果为未定义。 |