Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!mailrus!cornell!uw-beaver!ssc-vax!uvicctr!tholm From: tholm@uvicctr.UUCP (Terrence W. Holm) Newsgroups: comp.os.minix Subject: varargs(3) Message-ID: <506@uvicctr.UUCP> Date: 20 Sep 88 21:26:51 GMT Reply-To: tholm@uvicctr.UUCP (Terrence W. Holm) Organization: University of Victoria, Victoria B.C. Canada Lines: 59 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 #includeX 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 . X Subroutines should begin, as shown above, with an argument X and the declaration . X X A "pointer" into the argument list is declared with the type X . 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 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