Article View: comp.unix.programmer
Article #3509Re: Variable length arg lists in C (gcc): stdarg vs. varargs
From: Kenny McCormack
Date: Wed, 11 Oct 2000 00:00
Date: Wed, 11 Oct 2000 00:00
47 lines
2934 bytes
2934 bytes
In article <xm2F5.47$xe3.691@burlma1-snr2>, Barry Margolin <barmar@genuity.net> wrote: ... >Basically, K&R C had varargs. The standardization committee designed >stdargs as the replacement for it. The main difference has to do with the >fact that stdargs is designed to coexist with function prototypes, i.e. the >funcname(<fixed args>,...) notation. I can't quite parse your meaning here. Are you saying that varargs did not have the "at least one fixed arg" requirement? If so, then that's what I meant in the original post when I stated that it was my understanding that varargs was more powerful (I.e., more powerful b/c it did not have this requirement/limitation) >>What I'd like to see is an implementation of the max() function that doesn't >>require a 0 to be passed to signal the end of the list (and, consequently, >>has the limitation that 0 can't be a valid data point). > >Neither varargs nor stdargs provides a way to find out how many arguments >were passed. If you don't want to pass a marker for the end of the list, >pass the number of arguments as the first argument, e.g. > >max(5, 100, 0, -10, 150, 9) > >This also solves the problem of requiring at least one fixed argument for >this function. OK. Point taken. >>But thanks for the note about vprintf - this seems to imply that there >>should be wrapper functions provided by the system for any "standard" >>functions that take variable numbers of args. I note that there is a >>vscanf; are there any other standard functions that take variable numbers of >>args? (I can't think of any off hand, but I haven't tried very hard...) > >Are you asking about functions that take variable number of arguments, or >functions like vprintf, that take an explicit va_list argument. Functions like printf and scanf that take a variable number of args. My point, made also by another poster, is that a well designed "function that takes variable numbers of args" will also come in the form of a companion function that takes a va_list arg. >I don't think there's a vscanf(), though (it's not on my Solaris 2.6 >system). Present on Linux, but not on Solaris (AFAICT).
Technical Details
Message-ID:
<8s2tvu$duk$1@yin.interaccess.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8s26b3$9vl$1@yin.interaccess.com> <8s2a3q$ur8$1@flotsam.uits.indiana.edu> <8s2apd$aqe$1@yin.interaccess.com> <xm2F5.47$xe3.691@burlma1-snr2>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,22450a31b48667a4 X-Google-Attributes: gidfc89c,public X-Google-Thread: f65d0,22450a31b48667a4 X-Google-Attributes: gidf65d0,public From: gazelle@yin.interaccess.com (Kenny McCormack) Subject: Re: Variable length arg lists in C (gcc): stdarg vs. varargs Date: 2000/10/11 Message-ID: <8s2tvu$duk$1@yin.interaccess.com> X-Deja-AN: 680364015 References: <8s26b3$9vl$1@yin.interaccess.com> <8s2a3q$ur8$1@flotsam.uits.indiana.edu> <8s2apd$aqe$1@yin.interaccess.com> <xm2F5.47$xe3.691@burlma1-snr2> Organization: The official candy of the new Millennium Reply-To: gazelle@interaccess.com Newsgroups: comp.unix.programmer,gnu.gcc X-Complaints-To: newsabuse@supernews.com