Article View: comp.unix.programmer
Article #3514Re: Variable length arg lists in C (gcc): stdarg vs. varargs
From: Barry Margolin
Date: Wed, 11 Oct 2000 00:00
Date: Wed, 11 Oct 2000 00:00
41 lines
2968 bytes
2968 bytes
In article <8s2apd$aqe$1@yin.interaccess.com>, Kenny McCormack <gazelle@interaccess.com> wrote: >The goal is not to solve any particular problem (other than the "find the >maximum of a list of numbers" problem shown above), but rather to understand >how the various implementations (of the variable args functionality) work. 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. >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. >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. I don't think there's a vscanf(), though (it's not on my Solaris 2.6 system). -- Barry Margolin, barmar@genuity.net Genuity, Burlington, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Technical Details
Message-ID:
<xm2F5.47$xe3.691@burlma1-snr2>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>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: Barry Margolin <barmar@genuity.net> Subject: Re: Variable length arg lists in C (gcc): stdarg vs. varargs Date: 2000/10/11 Message-ID: <xm2F5.47$xe3.691@burlma1-snr2> X-Deja-AN: 680250944 Distribution: world References: <8s26b3$9vl$1@yin.interaccess.com> <8s2a3q$ur8$1@flotsam.uits.indiana.edu> <8s2apd$aqe$1@yin.interaccess.com> X-Abuse-Info: Otherwise we will be unable to process your complaint properly X-Complaints-To: abuse@gtei.net X-Trace: +ryjt60jnVPnPD4jV9N4s1kT6l3x2xfj146IJx3uJvoBEe2afpVFObe9anJBUiGosepqyaXm/dkC!UvUXnOR1PMj4MsShsI1IeDM/0EnWWlQg3UHlVqejuz/1N564YEZBFNqCIQ== Organization: Genuity, Cambridge, MA X-Copies-To: never NNTP-Posting-Date: Wed, 11 Oct 2000 18:31:57 GMT Newsgroups: comp.unix.programmer,gnu.gcc Originator: barmar@genuity.net (Barry Margolin)