home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16657 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.0 KB

  1. Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!henson!n8743196
  2. From: n8743196@henson.cc.wwu.edu (Jeff Wandling)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Multiple Parameter Passing (unspecified number)
  5. Message-ID: <1992Nov17.105837.21867@henson.cc.wwu.edu>
  6. Date: 17 Nov 92 10:58:37 GMT
  7. Article-I.D.: henson.1992Nov17.105837.21867
  8. References: <92321.124834GNR100@psuvm.psu.edu> <1992Nov17.093123@rbg.informatik.th-darmstadt.de>
  9. Organization: Howling Dog
  10. Lines: 52
  11.  
  12. misar@rbg.informatik.th-darmstadt.de (walter misar) writes:
  13.  
  14. >In article <92321.124834GNR100@psuvm.psu.edu>, <GNR100@psuvm.psu.edu> writes:
  15. >>    Hi.
  16. >> 
  17. >>    I'm looking to write a function that accepts any number of paramerter.
  18. >> There will be at least two, an int and a char[]. The rest will all be char[]'s.
  19. >> I need to know how this is done.  The meathod would be similar to that of
  20. >> printf(), so if anybody know how that works, please let me know.
  21.  
  22. >If you use an ANSI compiler it will look like this:
  23.  
  24. >#include <stdarg.h>
  25.  
  26. >void fun(int i,char s[],...)    /* 3 dots exactly    */
  27. >{  va_list argp;
  28. >    /* more variables */
  29.  
  30. >   va_start(argp,s);        /* 2nd arg is last named fun-arg    */
  31. >    /* with va_arg(argp, TYPENAME) you can step through the arg-list,
  32. >       the macro will provide always the next one, TYPENAME is the type
  33. >       of the arg (in this case char * or char [])
  34. >    */
  35. >    /* some code */
  36. >    va_end(argp);
  37.  
  38. >}
  39.  
  40. System: Sun 3/50, SunOS 4.1.1b
  41.  
  42. I'm trying to do a similar thing, except my function doesn't know what type
  43. to expect.  The next "variable argument" could be any simple type.  How
  44. do I deal with this?  Is there a way to switch on the type of the next
  45. argument? When using union's for example---
  46.  
  47.  
  48.   hash_insert(table,name,...) 
  49.   ....
  50.   {
  51.     
  52.     ....
  53.     va_list argp;
  54.  
  55.     type = va_"type?"(argp,???);
  56.     
  57.     ....
  58.    }
  59.  
  60. -- 
  61. perl -e '$a="Japhuneasorcttlk h eae r r ,";$]=0;$s=$];while($s<4){do{$_ .= pack
  62. ("c",vec($a,$],8));$]+=4;}while($]<length($a)&&vec($a,$],8)!=32);$s++;$]=$s;$_
  63. .= ' ';}chop;print;' Jeff Wandling  <jdw@physics.wwu.edu>  "will hack for food"
  64.