Xref: utzoo comp.unix.wizards:20253 comp.lang.c:25234 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: How does a VARARGS function call another VARARGS function? Keywords: VARARGS Message-ID: <21975@mimsy.umd.edu> Date: 21 Jan 90 10:20:26 GMT References: <439@gtenmc.UUCP> Followup-To: comp.lang.c Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 30 [How about that, a question in comp.unix.wizards that belongs in comp.lang.c, rather than the other way around....] [No need to include text; the subject line suffices. For those with notes or other subject-truncating systems, it is: How does a VARARGS function call another VARARGS function?] It does not. There is no portable way for one function of variable arguments to pass those arguments to another function of variable arguments. This is why vfprintf, vsprintf, and vprintf exist: a function with variable arguments that wants to print those arguments a la printf() must call vprintf. vprintf is just like printf, except that instead of a variable argument list, it takes a `va_list' parameter that describes some other function's variable argument list: /* foo(fmt, arg1, arg2) is like fprintf(stderr, fmt, arg1, arg2) */ int foo(const char *fmt, ...) { int ret, err; va_list ap; va_start(ap, fmt); ret = vfprintf(stderr, fmt, ap); if ((err = fflush(stderr)) != 0) ret = err; va_end(ap); return ret; } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris