variable number of arguments

Scott E. Schwartz schwartz at gondor.cs.psu.edu
Sat Feb 20 10:23:10 AEST 1988


In article <1608 at byzantium.UUCP> richwill at byzantium.UUCP (Rich Williamson) writes:
>I'm trying to put together a simple formatted output routine for 
>X-Windows. I would like to be able to say something like this

>  MyXText( X, Y, formatString, arg1, ... , argn );

>I would like to pass the necessary parameters to sprintf but I
>don't know how to declare the arguments to MyXText.  I don't know
>how to declare a variable number of arguments.  Is it even possible?
>The family of printf() functions seem to be able to receive variable
>arguments, so it would seem to possible.

Hi Rich, how's life back at Swat?   Anyway, you should look at the
man page for varargs.   Varargs is the only portable way to pass
a varying number of arguments to a procedure.  Since you want to
use sprintf inside of MyXText, and since you are using a Sun with
System V compatible libraries, you should strongly consider using
vsprintf(), which directly takes the (varargs definded) parameters
to MyXText, saving you from having to unpack arg1...argn and pass
them to sprintf().



-- Scott Schwartz            schwartz at gondor.cs.psu.edu



More information about the Comp.lang.c mailing list