Xref: utzoo comp.unix.wizards:5837 comp.lang.c:5764 Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: (simple?) varargs question Message-ID: <9917@mimsy.UUCP> Date: 21 Dec 87 21:38:55 GMT References: <10937@brl-adm.ARPA> Followup-To: comp.lang.c Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 46 [Followups redirected to comp.lang.c] In article <10937@brl-adm.ARPA> mrose@twg.arpa (Marshall Rose) writes: >... I want to be able to do upto several levels of nesting of routines >with variable arguments. The hierarchy is like this: [pretty picture deleted; pktlose calls saplose; xsprintf and saplose both call asprintf] >Each of these routines starts with a fixed number of arguments, >followed by a format string and then a variable number of >arguments. Ultimately asprintf will call vsprintf or _doprnt to >format a string. All the intermediate functions need `variadic' forms. It seems to me best to write *all* varadic functions with both forms, thus: /* pktlose(int a, int b, const char *fmt, ...) */ pktlose(va_alist) va_dcl { va_list l; /* va_start(fmt, l) */ va_start(l); vpktlose(l); va_end(l); } /* vpktlose(va_list ap) */ vpktlose(ap) va_list ap; { int a, b; a = va_arg(ap, int); b = va_arg(ap, int); ... vsprintf(buffer, ap); } Note that if you want to scan the `fmt' argument in vpktlose, you are out of luck, since vsprintf needs it too and there is no (portable) way to back up `ap'. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris