home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12406 < prev    next >
Encoding:
Internet Message Format  |  1992-08-16  |  1.9 KB

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