Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!hao!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: using varargs function to call another varargs function Message-ID: <7268@mimsy.UUCP> Date: Tue, 30-Jun-87 18:45:55 EDT Article-I.D.: mimsy.7268 Posted: Tue Jun 30 18:45:55 1987 Date-Received: Wed, 1-Jul-87 06:52:05 EDT References: <1332@rosevax.Rosemount.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 62 In article <1332@rosevax.Rosemount.COM> dave@rosesun.Rosemount.COM (Dave Marquardt) writes: >#include > >WINDOW *window1; > >dprintf(a,b,s,va_alist) >int a,b; >char *s; >va_dcl >{ > wmove(window1, a, b); > wprintw(window1, s, va_alist); >} > >First off, can you do something like this? No. >Secondly, I doubt that I have the syntax right. That is close enough. There are two problems. First, varargs is (as far as I can tell) only `kosher' when used for all the arguments. (The dpANS stdarg variable-argument-list mechanism works differently, and so I consider this a minor violation. Declaring a few fixed arguments seems to work in all the implementations I have used.) More important, though, is that wprintw takes a variable argument list, not a single argument of type `va_list'. System V has some of what you need in the form of `vprintf'. If curses had a wvprintw, you could do this: #include #include WINDOW *window1; dprintf(va_alist) va_dcl { int a, b; char *fmt; va_list l; va_start(l); a = va_arg(l, int); b = va_arg(l, int); fmt = va_arg(l, char *); wmove(window1, a, b); wvprintw(window1, fmt, l); } `vprintf' takes a format and an argument of type `va_list'. vfprintf takes one additional file pointer, and vsprintf takes a string pointer. All return the number of characters printed. This is clearly the Right Way to allow this sort of thing; indeed, it suggests that printf, fprintf, and sprintf themselves be implemented using (or ), and hence portable. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: seismo!mimsy!chris