Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!cornell!uw-beaver!uw-june!ka From: ka@june.cs.washington.edu (Kenneth Almquist) Newsgroups: comp.lang.c Subject: Re: passing variable numbers of arguments Message-ID: <6898@june.cs.washington.edu> Date: 9 Jan 89 04:12:55 GMT References: <899@thor.stolaf.edu> <15341@mimsy.UUCP> Distribution: na Organization: U of Washington, Computer Science, Seattle Lines: 39 Chris Torek gives some code for the situation in which one routine with a variable number of arguments wants to have these arguments interpreted by a different routine. (See the end of this article.) I've used the same approach for lack of anything better, but is it portable? The manual page for varargs doesn't say anything about the effects of passing the va_list variable to another routine. The vprintf family of routines are defined to accept va_list arguments, which should encourage implementors to make this work, but doesn't force them to. (They could have vprintf perform some special operations to simulate the environment of its caller before using va_arg.) Perhaps the definition of the stdarg mechanism is more specific? Also, I'm curious about why Ansi C uses the stdarg mechanism instead of varargs. I would think that varargs would be easier to implement. On machines with simple calling conventions varargs requires no compiler support; on other machines varargs is likely to require fewer special cases than stdarg since either all or none of the arguments are handled by the varargs mechanism. Kenneth Almquist bar(va_alist) va_dcl { va_list ap; va_start(ap); vbar(ap); va_end(ap); } vbar(ap) va_list ap; { ... code to deal with variable arguments ... ... [uses va_arg(ap, type) to access arguments to "bar"] ... }