[comp.lang.c] Variable arguments to & from functions.

akshay@cbnewsm.att.com (akshay.kumar.deshpande) (06/18/91)

I am trying to write a variable argument function which in turn
calls another variable argument function. Can anybody tell me how
to pass the unknown arguments I receive to the next function.
Here is a psuedo example:

A(int arg1, ...)
{

	.
	.

	va_start(ap, fmt);  /* from K&R 2nd edition - p 156 */

	.

	B(arg1, arg2, arg3, <...>);

	.

}

B(int arg1, int arg2, int arg3, ...);
{
.
.
.

}

I would like to have the "..." of A match that for the function
call of B.

-akshay
speedy@att.att.com 
(908) 957-3252

mouse@thunder.mcrcim.mcgill.edu (der Mouse) (06/18/91)

In article <1991Jun17.205314.25401@cbnewsm.att.com>, akshay@cbnewsm.att.com (akshay.kumar.deshpande) writes:

> I am trying to write a variable argument function which in turn calls
> another variable argument function.  Can anybody tell me how to pass
> the unknown arguments I receive to the next function.
(Questions generally end with `?' instead of `.'.)

> Here is a psuedo example:

[compressed -dM]
> A(int arg1, ...) {
> 	va_start(ap, fmt);  /* from K&R 2nd edition - p 156 */
> 	B(arg1, arg2, arg3, <...>);
> }

> B(int arg1, int arg2, int arg3, ...); { ... }

> I would like to have the "..." of A match that for the function call
> of B.

Sorry, can't be done.  You have to provide a v- form of B that takes a
va_list parameter and then call that from A.  (You should probably do
this anyway; in fact, a normal thing to do would be to have B just call
its varargs version.)

Note also that va_start takes the name of the last fixed argument,
which is arg1, not fmt.  (You can't just blindly copy code from K&R;
you have to understand it first, if only minimally.)

Something like (declarations omitted; also don't forget the va_end()
calls)

A(int arg1, ...) {
	va_start(ap, arg1);
	vB(arg1, arg2, arg3, ap);
}

B(int arg1, int arg2, int arg3, ...); {
	va_start(ap,arg3);
	vB(arg1,arg2,arg3,ap);
}

vB(int arg1, int arg2, int arg3, va_list ap) {
	...do the real B here...
}

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu