home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!sdd.hp.com!nigel.msen.com!yale.edu!ira.uka.de!uka!news.ira.uka.de!rose
- From: rose@tmipi5.telematik.informatik.uni-karlsruhe.de (Ortwin Rose)
- Newsgroups: comp.lang.c++
- Subject: Re: using (...) question
- Date: 17 Aug 92 08:25:50
- Organization: /usr/users/rose/.organization
- Lines: 32
- Message-ID: <ROSE.92Aug17082550@tmipi5.telematik.informatik.uni-karlsruhe.de>
- References: <J3mkPB8w165w@toz.buffalo.ny.us>
- NNTP-Posting-Host: tmipi5.telematik.informatik.uni-karlsruhe.de
- In-reply-to: cyberman@toz.buffalo.ny.us's message of 15 Aug 92 23:28:42 GMT
-
-
- I suggest you use the method defined in <stdarg.h>, if you know the
- first parameter that is passed to your function (as in printf(char *, ...)).
- Also possible is using <varargs.h>, however, it will fail on some machines
- (such as MIPS-based RISCs) under certain circumstances. Compare also the
- ARM, p. 146 where the usage of a variable number of arguments is explained
- in detail. Here is a short example how to use the stuff declared there:
-
- void dummy (char* form, ...)
- {
- va_list ap; // must declare this to access params
-
- va_start(ap, form); // and initialize it (using the last NAMED argument
- // in the argument list. Now 'ap' points to the first
- // of the unnamed parameters.
-
- <type> va_arg(ap, <type>); // <type> is the type of the next argument
- // in the argument list, and va_arg() will
- // return a value of type <type> from the
- // argument list and will modify 'ap' to point
- // to the next argument. Repeated use of va_arg()
- // will give you all the unnamed arguments.
-
- va_end(ap); // MUST call it to clean up
- }
-
-
- Regards
-
- -- O. Rose
- University of Karlsruhe
- Institute of Telematics
-