home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18380 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  1.3 KB

  1. Path: sparky!uunet!usc!rutgers!mcdhup!src4src!wozzle!alane
  2. From: alane@wozzle.linet.org (J. Alan Eldridge)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Variable Length Argument Lists?
  5. Message-ID: <XFDqVB4w165w@wozzle.linet.org>
  6. Date: 13 Dec 92 17:07:56 GMT
  7. References: <SR.92Dec3164104@zen.mp.umist.ac.uk>
  8. Organization: Disorganization
  9. Lines: 42
  10.  
  11. sr@zen.mp.umist.ac.uk (Simon Read) writes:
  12.  
  13. > What I want to be able to do is to prune off a few of the arguments in
  14. > an ... list and pass the rest on to another function. Something like
  15. > the following C-style code would suggest:
  16. > void recursive1 (int a, ...)
  17. > {
  18. >     printf("%d, ", a);
  19. >     if (a == 0)
  20. >     recursive1(...);
  21. >     else
  22. >     recursive1(a, ...);
  23. > }
  24.  
  25. You can't get there from here. Best you could do, and this isn't really
  26. very safe at all, is:
  27.  
  28. void rhelper(va_list ap)
  29. {
  30.     va_list asave = ap;
  31.  
  32.     int a = va_arg(ap,int);
  33.  
  34.     if (a == 0)
  35.         rhelper(ap);
  36.     else
  37.         rhelper(asave);
  38. }
  39.  
  40. void recursive1(int a, ...)
  41. {
  42.     rhelper((va_list)&a);
  43. }
  44.  
  45. Please, folks, no flames. I merely suggest how he can accomplish his
  46. objective, I do _not_ recommend the practice, nor do I claim it will 
  47. even work on all architectures.
  48.  
  49.     
  50. alane@wozzle.linet.org (J. Alan Eldridge)
  51. Fido: The University of Walamaloo 1:272/38.473
  52.