Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: Variable number of arguments Message-ID: <726@taumet.com> Date: 14 May 91 21:44:16 GMT References: <1991May13.210257.20240@cunixf.cc.columbia.edu> Organization: Taumetric Corporation, San Diego Lines: 23 ta-dw30@cunixa.cc.columbia.edu (David Worenklein) writes: >I know I can pull a variable number of arguments off of the stack using va_... >but how do I know how many arguments are there? Is there any way to get the >C compiler to push all the arguments and then push the number of (arguments, >bytes, etc.) pushed? >PS I'm using Symantec Think C v4 so if it has some feature that ANSI doesn't... There is no portable way to do this; I don't know whether Think C provides some extension. One of the requirements of writing such a function is that one of the fixed arguments must explicitly or implicitly provide information about the number and type of the arguments. For example, the printf/scanf families interpret the fixed string argument to determine what the remaining arguments are. If you have a function which expects a variable number of args all of the same type, it would be sufficient to have a fixed arg containing the number of args. Alternatively, if there is an "impossible" value for the arg type (NULL pointer, a count of -1), you can use that value as a flag for the end of the args. -- Steve Clamage, TauMetric Corp, steve@taumet.com