Content deleted Content added
Hopefully fixed the last typo in the note Tags: Mobile edit Mobile web edit Advanced mobile edit |
→In C: Name the note to fix it not showing up when clicked on Tags: Mobile edit Mobile web edit Advanced mobile edit |
||
Line 49:
{{code|stdarg.h}} declares a type, {{code|va_list}}, and defines four macros: [[va_start|{{code|va_start}}]], [[va_arg|{{code|va_arg}}]], [[va_copy|{{code|va_copy}}]], and [[va_end|{{code|va_end}}]]. Each invocation of {{code|va_start}} and {{code|va_copy}} must be matched by a corresponding invocation of {{code|va_end}}. When working with variable arguments, a function normally declares a variable of type {{code|va_list}} ({{code|ap}} in the example) that will be manipulated by the macros.
# {{code|va_start}} takes two arguments, a {{code|va_list}} object and a reference to the function's last parameter (the one before the ellipsis; the macro uses this to get its bearings). In [[C2x|C23]], the second argument will no longer be required and variadic functions will no longer need a named parameter before the ellipsis.{{r|
# {{code|va_arg}} takes two arguments, a {{code|va_list}} object (previously initialised) and a type descriptor. It expands to the next variable argument, and has the specified type. Successive invocations of {{code|va_arg}} allow processing each of the variable arguments in turn. Unspecified behavior occurs if the type is incorrect or there is no next variable argument.
# {{code|va_end}} takes one argument, a {{code|va_list}} object. It serves to clean up. If one wanted to, for instance, scan the variable arguments more than once, the programmer would re-initialise your {{code|va_list}} object by invoking {{code|va_end}} and then {{code|va_start}} again on it.
|