VARARGS(3) COMMAND REFERENCE VARARGS(3)
NAME
varargs - variable argument list
SYNOPSIS
#include <varargs.h>
function( vaalist )
vadcl
valist pvar ;
vastart( pvar );
f = vaarg( pvar , type );
vaend( pvar );
DESCRIPTION
This set of macros provides a means of writing portable
procedures that accept variable argument lists. Routines
having variable argument lists (such as printf(3s)) that do
not use varargs are inherently nonportable, since different
machines use different argument passing conventions.
Vaalist is used in a function header to declare a variable
argument list.
Vadcl is a declaration for vaalist. Note that there is no
semicolon after vadcl.
Valist is a type which can be used for the variable pvar,
which is used to traverse the list. One such variable must
always be declared.
Vastart(pvar) is called to initialize pvar to the beginning
of the list.
Vaarg(pvar, type) will return the next argument in the list
pointed to by pvar. Type is the type the argument it is
expected to be. Different types can be mixed, but it is up
to the routine to know what type of argument is expected,
since it cannot be determined at run-time.
Vaend(pvar) is used to finish up.
Multiple traversals, each bracketted by vastart ...
vaend, are possible.
EXAMPLES
The following subroutine executes the given filename with
the given arguments. The first argument must be a filename,
and the last argument must be a 0.
#include <varargs.h>
Printed 10/17/86 1
VARARGS(3) COMMAND REFERENCE VARARGS(3)
execl(va_alist)
va_dcl
{
va_list ap;
char *filename;
char *args[100];
int argno = 0;
va_start(ap);
filename = va_arg(ap, char *);
while (args[argno++] = va_arg(ap, char *))
;
va_end(ap);
return execv(filename, args);
}
CAVEATS
It is up to the calling routine to determine how many
arguments there are, since it is not possible to determine
this from the stack frame. For example, execl passes a 0 to
signal the end of the list. Printf can tell how many
arguments are supposed to be there by the format.
SEE ALSO
nargs(3c).
Printed 10/17/86 2
%%index%%
na:72,68;
sy:140,837;
de:977,1787;
ex:2764,260;3168,362;
ca:3530,419;
se:3949,107;
%%index%%000000000116