Path: utzoo!attcan!uunet!husc6!bu-cs!mirror!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: passing variable numbers of arguments Keywords: varargs assert() nargs() Message-ID: <11555@haddock.ima.isc.com> Date: 26 Jan 89 23:41:15 GMT References: <11378@haddock.ima.isc.com> <9321@smoke.BRL.MIL> <11410@haddock.ima.isc.com> <9358@smoke.BRL.MIL> <202@mstan.Morgan.COM> <9381@smoke.BRL.MIL> <11428@haddock.ima.isc.com> <203@s5.Morgan.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 22 In article <203@s5.Morgan.COM> dff@Morgan.COM (Daniel F. Fisher) writes: >In article <11428@haddock.ima.isc.com> karl@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@haddock.isc.com), The Walking Lint