The va_arg , va_start and va_end macros allow portable procedures that accept variable argument lists, as defined in stdarg.h , to be written. They are used to process a list of arguments which may vary in number and type at each function call. va_arg returns the data type and value of the next argument in a variable argument list ap, starting with the first argument. Technically speaking, the macro expands into an expression of the data type and value of the argument.
The variable argument list to which ap points must be initialized with va_start before the first call to va_arg . Each invocation of va_arg modifies ap so that the value of the next argument in turn is returned. ap is a pointer to the argument list initialized with va_start before va_arg is called for the first time. type is a type name matching the type of the current argument. Any C data type, for which a pointer to an object of the specified type is defined by simply appending an * to type, is allowed. Array and function types, for example, are invalid. If there is no next argument or if type does not match the current argument, the behavior is undefined. |