Variadic functions are functions which can take in a variable number of arguments. The C language by itself provides no special syntax for dealing with them, but variadic functions are supported by the standard C library (
A variadic function is declared as:
Where MyFunction is defined as a function which takes 1 required argument, and as many non-optional arguments as you want (up to the practical limit set by the maximum number of function arguments you are allowed).
A variadic function is defined as:
But how do you access the variable arguments in your function definition? Use the function-like macros
va_end provided by
The second argument passed to
va_arg, type, must be a self-promoting type.
For most compilers, va_end does nothing (including the GCC compiler). But you should always include it for portability reasons.
This work is licensed under a Creative Commons Attribution 4.0 International License .