Path: utzoo!mnetor!uunet!vsi!friedl From: friedl@vsi.UUCP (Stephen J. Friedl) Newsgroups: comp.lang.c Subject: Re: variable number of arguments Message-ID: <51@vsi.UUCP> Date: 26 Feb 88 05:22:57 GMT References: <1608@byzantium.UUCP> <1632@mhres.mh.nl> Organization: V-Systems, Inc. -- Santa Ana, CA Lines: 50 Keywords: arguments, varargs Summary: suggested fix to the example In article <1632@mhres.mh.nl>, hst@mhres.mh.nl (Klaas Hemstra) writes: > Try using the vsprintf() function together with varargs. > Example: > > MyXText( X, Y, formatString, va_alist) > .... > va_dcl > { char TempString[100]; > va_list args; > > va_start(args); > vsprintf(TempString , formatString, args); > > va_end(args); > > } I think you are better with: MyXText(va_alist) va_dcl { char buf[256]; /* buffer to format to */ int x, y; /* X/Y location */ char *fmt; /* printf format string */ va_args args; va_start(args); x = va_arg(args, int); /* GET... */ y = va_arg(args, int); /* .. ALL... */ fmt = va_arg(args, char *); /* .... ARGS.. */ vsprintf(buf, fmt, args); va_end(args); } I have no specific reason to doubt the portability, but it strikes me that since args are so crazy on various machines (stack grows up, stack grows down, params passed in registers, etc.) that letting varargs handle *all* the details would not be a bad idea. Just a thought, Steve -- Life : Stephen J. Friedl @ V-Systems, Inc/Santa Ana, CA *Hi Mom* CSNet: friedl%vsi.uucp@kent.edu ARPA: friedl%vsi.uucp@uunet.uu.net uucp : {kentvax, uunet, attmail, ihnp4!amdcad!uport}!vsi!friedl