Path: utzoo!mnetor!uunet!husc6!tut.cis.ohio-state.edu!lvc
From: lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani)
Newsgroups: comp.lang.c
Subject: Re: Variable argument lists.
Message-ID: <12933@tut.cis.ohio-state.edu>
Date: 10 May 88 23:13:16 GMT
References: <14139@brl-adm.ARPA>
Organization: Ohio State Computer & Info Science
Lines: 41
Summary: scan the argument list twice

In article <14139@brl-adm.ARPA>, bates%falcon.dnet%fermat@bru.mayo.edu (Cary Bates) writes:
> 
>        Does anybody know (or care) why in ANSI standard C when 
>        using a variable length argument list, there is no way to 
>        determine how many arguments where passed into the function?

In this example (with ) I scan the argument list
twice.  Once to get a count, the next to do the real work.
Something similar should work in ANSI.  Can anyone tell me
if I'm wrong (again! :-( ).  This assumes all the arguments
are char* but it could be changed for a fixed number leading
args and a variable number of other things.

#include 

splat(va_alist)
	va_dcl
{
	va_list ap;
	register unsigned cnt = 0;
	int something;
	char *pi;

	va_start(ap);	/* arg setup */

	while ((pi = va_arg(ap, char *)) != (char *)0)
		cnt++;

	va_end(ap);	/* arg cleanup */

	va_start(ap);	/* arg setup again */

	...whatever...

	va_end(ap);	/* arg cleanup again */
	return something;
}
-- 
Larry Cipriani, AT&T Network Systems and Ohio State University
Domain: lvc@tut.cis.ohio-state.edu
Path: ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!lvc (weird but right)