Content deleted Content added
Sietse Snel (talk | contribs) m dab |
m sp, date & link fixes; unlinking common words using AWB |
||
Line 1:
{{Redirect|varargs|the varargs.h library in [[C (programming language)|C]]|varargs.h}}
In [[computer programming]], a '''variadic function''' is a [[function (programming)|function]] of variable [[arity]]; that is, one which can take different numbers of arguments. Support for variadic functions differs widely among [[programming language]]s.
Line 9:
Variadic functions can expose type-safety problems in some languages. For instance, C's <TT>printf</TT>, if used uncautiously, can give rise to a class of security holes known as [[format string attack]]s. The attack is possible because the language support for variadic functions is not [[type safety|type-safe]]; it permits the function to attempt to pop more arguments off the stack than were placed there -- corrupting the stack and leading to unexpected behavior.
== Variadic functions in
To portably implement variadic functions in the C programming language, the standard [http://www.opengroup.org/onlinepubs/009695399/basedefs/stdarg.h.html <tt><stdarg.h></tt>] header file should be used. The older [http://www.opengroup.org/onlinepubs/007908799/xsh/varargs.h.html <tt><varargs.h></tt>] header has been deprecated in favor of
The variadic function feature is going to be present in the upcoming
template<typename T>
Line 35:
class tuple<>;
== Variadic functions in
In
== Variadic functions in
Other languages, such as
public static void printSpaced(Object... objects) {
Line 51:
// printSpaced(1, 2, "three");
▲== Variadic functions in [[Python (programming language)|Python]] ==
{{section-stub}}
[[Python (programming language)|Python]] supports very flexible variadic functions. By marking variables with one asterisk (e.g. *var) the given variable is defined to be a tuple of all the extra arguments. By marking variables with two asterisks (e.g. **var) the given variable is a dictionary of all extra [[Parameter (computer science)
def f(*args, **kwargs):
Line 90 ⟶ 89:
==See also==
* [[Variadic macro]] (C
* [[Java syntax]]
[[Category:Programming constructs]]
[[Category:Programming language topics]]
|