[comp.std.c] varargs vs. prototypes

rfg@pink.ACA.MCC.COM (Ron Guilmette) (06/08/89)

Sorry if this has been covered before, but I'd like to know
one little thing.

Old (non-prototype) function declarations & definitions have
been depreciated right?  So we really should *not* be using
the old style anymore right?  We should do everything with
prototypes right?

So how can I write a function definition for a varargs function
using prototypes?  Is this possible?


-- 
// Ron Guilmette  -  MCC  -  Experimental Systems Kit Project
// 3500 West Balcones Center Drive,  Austin, TX  78759  -  (512)338-3740
// ARPA: rfg@mcc.com
// UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg

gwyn@smoke.BRL.MIL (Doug Gwyn) (06/09/89)

In article <237@pink.ACA.MCC.COM> rfg@MCC.COM (Ron Guilmette) writes:
>Old (non-prototype) function declarations & definitions have
>been depreciated right?  So we really should *not* be using
>the old style anymore right?  We should do everything with
>prototypes right?

If you don't care about non standard-conforming implementations,
then you should use prototypes.  Otherwise, you should use the
__STDC__ predefined macro to select whether to use prototypes or
old-style declarations.  Some clever tricks to assist in this
have been previously posted, but you can do it the obvious way..

>So how can I write a function definition for a varargs function
>using prototypes?  Is this possible?

#include <stdarg.h>
ret_type func_name( type1 fixed_arg1, typen fixed_argn, ... )
	{ /* stuff using the va_* macros defined by <stdarg.h> */ }

rfg@pink.ACA.MCC.COM (Ron Guilmette) (06/10/89)

In article <10380@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>In article <237@pink.ACA.MCC.COM> rfg@MCC.COM (Ron Guilmette) writes:
>>So how can I write a function definition for a varargs function
>>using prototypes?  Is this possible?
>
>#include <stdarg.h>
>ret_type func_name( type1 fixed_arg1, typen fixed_argn, ... )
>	{ /* stuff using the va_* macros defined by <stdarg.h> */ }


PLEASE!  EVERYONE!  I goofed!  Please don't send me anymore messages
showing me how to do this.  I know how to use prototypes and the
stuff from <stdarg.h> (or <varargs.h>) to get at the variable parameters.
I goofed because I asked the WRONG question.

The question I meant to ask was "How can you use prototypes for a function
which can accept ZERO or more arguments?"

There appears to be NO WAY to do this.

Since I asked the original question, I been informed that I should not
even be worring about the "ZERO or more" case because, in actual practice,
it never occurs.

I'm now mostly convinced that this is true, so my (intended) question is
moot.

-- 
// Ron Guilmette  -  MCC  -  Experimental Systems Kit Project
// 3500 West Balcones Center Drive,  Austin, TX  78759  -  (512)338-3740
// ARPA: rfg@mcc.com
// UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg