Path: utzoo!mnetor!uunet!mcvax!mhres!hst From: hst@mhres.mh.nl (Klaas Hemstra) Newsgroups: comp.lang.c Subject: Re: variable number of arguments Message-ID: <1632@mhres.mh.nl> Date: 23 Feb 88 08:30:16 GMT References: <1608@byzantium.UUCP> Reply-To: hst@mhres.mh.nl (Klaas Hemstra) Organization: Multihouse N.V., The Netherlands Lines: 31 Keywords: arguments Summary: Using varargs with or without vprintf,vsprintf or vfprintf 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); } Note that you have to include the varargs.h file. This file is present in most Unix systems and also with most non-Unix C compilers. Be carefull using varargs !! Recently I had some trouble using them. If you think they are REALLY flexible you are wrong. e.g.: You have a function accepting a variable number of arguments with the va_alist declaration. Then you can call this function with (..,a1,a2,...). But if you want to call the function from another function which also accepts a variable number of arguments, you can NOT pass that variable number of arguments to the first function mentioned. This is probably the reason why vprintf,vfprintf & vsprintf exist. Note that on some of the Unix systems I tried this was possible but not on all of them ! (I don't want a discussion on where you can and where you can't use this way of varargs passing).