Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Passing variable #of args Message-ID: <1989Jan22.025110.6210@utzoo.uucp> Organization: U of Toronto Zoology References: <470@marob.MASA.COM> Date: Sun, 22 Jan 89 02:51:10 GMT In article <470@marob.MASA.COM> daveh@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@zoo.toronto.edu