Path: utzoo!attcan!uunet!lll-winken!ames!ucsd!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: passing variable numbers of arguments Message-ID: <8708@alice.UUCP> Date: 9 Jan 89 03:50:03 GMT References: <899@thor.stolaf.edu> <15341@mimsy.UUCP> <449@marob.MASA.COM> Distribution: na Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 44 In article <449@marob.MASA.COM>, samperi@marob.MASA.COM (Dominick Samperi) writes: > In article <15341@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: > It seems that for the ANSI style varargs (that is, the one requiring > stdarg.h), at least one explicitly named arg must be included in the > function definition, so that there is a FIRST that can be supplied to > va_start, as in: > va_list ap ; > va_start(sp, FIRST) ; > x = va_arg(ap, TYPE) ; > va_end(ap) ; > Is this correct? Yes. > If not, how does one define a function with a variable > number of args, for which there are no explicitly named args? You can't. The rationale is that there is no reason ever to do so. After all, you have to know the type of the first argument somehow, and without looking at the argument list. > It also seems to be the case that it is not possible for a called function > (with a variable number of args) to determine how many args were actually > passed, or when the last arg has been fetched, unless this information is > supplied in the first parameter, say. Correct. > Wouldn't it have been reasonable for > the standard to specify that the compiler should enable the called function > to determine the number of parameters that were passed, by automatically > passing this information as a first implicit parameter, for example? Sure, but they didn't do it that way. For one thing, that would slow down every call a little. -- --Andrew Koenig ark@europa.att.com