A function is variadic if it can accept a variable number of arguments; that is, its arity is not fixed. The abbreviation "varargs" is commonly used to refer to these types of functions.
Variadic functions are functions which accept a variable number of arguments—for example, a function that may be called with either 1 or 2 arguments.
Most high level languages have support for variadic functions within the language's syntax proper. Some of these languages do not require extra syntax (for example, JavaScript, Perl, and PHP). They typically access variable arguments through some sort of default variable (Perl uses _@
).
Most compiled languages (for example, D, Java, C#, and VB.NET) and even some interpreted languages (for example, Python, CoffeeScript, Ruby, and Scheme) require explicit syntax in order to use variadic functions. They typically "roll" all excess arguments into a specially noted argument which can be accessed like an array (Python uses the *args
syntax, where *args
is a tuple
object).
C and C++ variadic functions use the standard library (<stdarg.h>
, C++ alternatively <cstdarg>
).
They use the va_*
functions in order to unpack and access variable numbers of arguments. See man stdarg
or ANSI section 2.10 for more information on these functions.