passing variable numbers of arguments

Karl Heuer karl at haddock.ima.isc.com
Fri Jan 27 09:41:15 AEST 1989


In article <203 at s5.Morgan.COM> dff at Morgan.COM (Daniel F. Fisher) writes:
>In article <11428 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer)
>[suggests that for most purposes] a boolean va_isarg() would suffice.
>
>I considered [that], but concluded that it is not appropriate, since the
>unavailability of a necessary argument represents a programming error which
>is best treated as an assertion failure.

Here's a counterexample.
	int min(int first, ...) {
	    int i;  va_list ap;
	    va_start(ap, first);
	    while (va_isarg(ap)) {
	        if ((i = va_arg(ap, int)) < first) first = i;
	    }
	    return (first);
	}

This function, which cannot be written in either pre-ANSI or ANSI C, uses
va_isarg() to obviate the need for an explicit extra argument.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list