Functions With Variable Number Of Arguments In C
by Peter Jay Salzman <p@dirac.org>
Overview
- Declare a special `pointer' variable of type va_list.
- Use va_start() to make the va_list point to the the
beginning of the argument list.
- Use va_arg() to retrieve arguments.
- Use va_end() to cleanup when you're done.
Prototypes
void va_start( va_list ap, last );
type va_arg( va_list ap, type );
void va_end( va_list ap );
Important Notes
- Prototypes, macro defs and structures provided in <stdarg.h>.
- Argument right before variable list must be `known'.
- Variables received will undergo default promotions for narrow types.
Next: Sample code