tholm@uvicctr.UUCP (Terrence W. Holm) (09/21/88)
EFTH MINIX report #47 - September 1988 - varargs(3) Varargs.h has been posted before - this time we also get a "man" page. ---------------------------------------------------------- echo x - varargs.3 gres '^X' '' > varargs.3 << '/' XSUBROUTINES X varargs(3) - accessing a variable length argument list X XINVOCATION X #include <varargs.h> X X f( va_alist ) X va_dcl X { X va_list p; X type arg; X . . . X va_start( p ); X arg = va_arg( p, type ); X . . . X va_end( p ); X } X XEXPLANATION X For portability, all functions which use variable length X argument lists should use the definitions from <varargs.h>. X Subroutines should begin, as shown above, with an argument X <va_alist> and the declaration <va_dcl>. X X A "pointer" into the argument list is declared with the type X <va_list>. va_start() must be done before the first use of X the pointer, and va_end() must be done after the last use. X Multiple va_start() ... va_end() segments are allowed. X X The list is accessed using va_arg(p,type). This returns the X value of the next element in the list. The <type> is the X type of the argument, for example (int). / echo x - varargs.h gres '^X' '' > varargs.h << '/' X/* varargs.h */ X Xtypedef char *va_list; X X#define va_dcl int va_alist; X#define va_start(p) (p) = (va_list) &va_alist; X#define va_arg(p,type) ( (type *) ((p)+=sizeof(type)) )[-1] X#define va_end(p) / ---------------------------------------------------------- Edwin L. Froese uw-beaver!ubc-cs!mprg!handel!froese Terrence W. Holm uw-beaver!uvicctr!tholm