.TH VARARGS 3 .CT 2 data_man .SH NAME varargs \(mi variable argument list .SH SYNOPSIS .nf .B #include .IB function (va_alist) .B va_dcl .PP .B va_list pvar; .PP .B va_start(pvar); .PP .B va_arg(pvar, type); .PP .B va_end(pvar); .fi .SH DESCRIPTION This set of macros allows portable procedures that accept variable argument lists to be written. Routines which have variable argument lists (such as .IR printf (3)) that do not use varargs are inherently nonportable, since different machines use different argument passing conventions. .PP The literal identifier .I va_alist is used in a function header to declare a variable argument list. It is declared by .I va_dcl. Note that there is no semicolon after .I va_dcl. .PP .B Va_list is the type of the variable .I pvar, which is used to traverse the list. One variable of this type must always be declared. .PP .I Va_start initializes .I pvar to the beginning of the list. .PP .I Va_arg returns the next argument in the list pointed to by .IR pvar . .I Type is the type the argument is expected to be. Different types can be mixed, but it is up to the routine to know what type is expected, since it cannot be determined at runtime. .PP .I Va_end is used to finish up. .PP Multiple traversals, each bracketed by .I va_start and .I va_end, are possible. .SH EXAMPLES How to define .I execl in terms of .IR execv ; see .IR exec (2): .IP .nf .ft L #include execl(va_alist) va_dcl { va_list ap; char *file; char *args[100]; int argno = 0; va_start(ap); file = va_arg(ap, char*); while(args[argno++] = va_arg(ap, char*)); va_end(ap); execv(file, args); } .fi .ft P