[comp.unix.wizards] How does a VARARGS function call another VARARGS function?

fst@gtenmc.UUCP (Fariborz "Skip" Tavakkolian) (01/18/90)

I think I have tried everything, though not sure. The problem looks like
this:

void error_function_1(file, line, errorlevel, fmt, va_alist)
	char *file, *fmt, *errorlevel;
	int line;
	va_dcl
	{
	va_list args;
	/* do stuff */
	error_function_2(errorlevel, fmt, args);
	/* do stuff */
	va_end();
	}

/* error_function_2 is another VARARGS function which uses vfprintf
 * for further processing
 */

Short of doing the ugly _arg1, _arg2, _arg3, ..., _arg1001, etc... is there
a ``right'' way of doing this?

Many thanks.

Skip
-- 
----------------------------------------------------------------------------
Fariborz "Skip" Tavakkolian  -of-  Automated Cellular Engineering
Currently consulting         -at-  GTE Telecom, Inc. Bothell, Wa
Mail:                              tiny1!fst@mcgp1  -or-  fst@gtenmc

chris@mimsy.umd.edu (Chris Torek) (01/21/90)

[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