May 11, 2021 C
The stdarg.h header file defines a variable type va_list and three macros that can be used to get parameters in a function when the number of parameters is unknown (i.e. the number of parameters is variable).
The function pass for variable parameters is used with an odd (or not) at the end of the argument ,... Defined.
Here are the types of variables defined in the header file stdarg.h:
Serial number | Variable & description |
---|---|
1 |
va_list
This is an application for va_start()、va_arg() with va_end() These three macros store information. |
Here are the macros defined in the header file stdarg.h:
Serial number | Macro & Description |
---|---|
1 |
void va_start(va_list ap, last_arg)
This macro initialization ap Variable, it va_arg with va_end The macro is used together. last_arg Is the last one of the known fixed parameters that passed to the function, that is, the parameters prior to the omitting number. |
2 |
type va_arg(va_list ap, type)
This macro search function parameter list is type The next parameter. |
3 |
void va_end(va_list ap)
This macro is allowed to use va_start Macro's function returned with variable parameters.If there is no call before returning from the function va_end The result is undefined. |