C language allows the use of variable parameter list, our usual printf function is variable parameter function, C standard library provides stdarg.h to provide us with this support; the header file provides some types and macros to support variable parameter lists, including type va_list, Macro Va_start, VA _arg, Va_end;
Variable function parameter definition method:
#include <stdarg.h>void func (int count,...) { va_list ap; int IX, TMP; Va_start (AP, a); For (Ix=0;ix < count; ++ix) { TMP = VA_ARG (AP, int); Process the Param } va_end (AP);}
The first parameter of the function, count, is essential, that is, you define a variable argument list function to have at least one parameter;
Va_list: It is generally defined as char *;
Va_start (va_list AP, Paramn): Initializes the value of the AP, pointing to the first mutable parameter
Va_arg (va_list AP, type): Will point from the AP according to the type to get the actual value and move the AP pointer
Va_end: Generally do not do anything
C-language function variable parameter list