List of variable parameters of c Functions
The C language allows the use of variable parameter lists. The commonly used printf function is a variable parameter function, and the C Standard Library provides stdarg. h provides us with support for this aspect; this header file provides some types and macros to support variable parameter lists, including types va_list, macros va_start, va_arg, and 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 count of a function is essential, that is, the variable parameter list function you define must have at least one parameter;
Va_list: It is generally defined as char *;
Va_start (va_list ap, paramN): Initialize the ap value, pointing to the first variable parameter.
Va_arg (va_list ap, TYPE): obtains the actual value from the ap based on the TYPE and moves the ap pointer.
Va_end: Generally, nothing is done.