Passing variable #of args

Henry Spencer henry at utzoo.uucp
Sun Jan 22 12:51:10 AEST 1989


In article <470 at marob.MASA.COM> daveh at marob.masa.com (Dave Hammond) writes:
>Given B() which expects 3 arguments passed to it, it's reasonably
>obvious what can occur when A() invokes B() and passes less than 3 args.

Oh really?  In a particular implementation, maybe.  Not in general.
About the only general prediction which can be made (which is probably
what Dave was thinking of) is "trouble".

>What potential problems exist if A() passes *more* than 3 args to B()?
>It seems to me that this would harm nothing, since the extra stuff
>ends up beyond the current stack position.

Stack?  What's that?  And why do you assume that extras end up on the
tail end?  They could just as easily end up on the front.  The only
general statement that can be made is "possible trouble".  You can get
away with it in some implementations, including many of the early C
implementations... but not all.

>lprintf(fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,10)
>char *fmt;
>{
>	char buf[BUFSIZ];
>	sprintf(buf,fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,10)
>	...
>}
>
>Given the availability of varargs, is this style still acceptable and,
>more importantly, is it portable?

It has never been portable.  Whether it is acceptable, or has ever been
acceptable, depends on who you ask; the answers at utzoo are "no" and "no".
-- 
Allegedly heard aboard Mir: "A |     Henry Spencer at U of Toronto Zoology
toast to comrade Van Allen!!"  | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list