home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!rutgers!mcdhup!src4src!wozzle!alane
- From: alane@wozzle.linet.org (J. Alan Eldridge)
- Newsgroups: comp.lang.c
- Subject: Re: Variable Length Argument Lists?
- Message-ID: <XFDqVB4w165w@wozzle.linet.org>
- Date: 13 Dec 92 17:07:56 GMT
- References: <SR.92Dec3164104@zen.mp.umist.ac.uk>
- Organization: Disorganization
- Lines: 42
-
- sr@zen.mp.umist.ac.uk (Simon Read) writes:
-
- > What I want to be able to do is to prune off a few of the arguments in
- > an ... list and pass the rest on to another function. Something like
- > the following C-style code would suggest:
- >
- > void recursive1 (int a, ...)
- > {
- > printf("%d, ", a);
- > if (a == 0)
- > recursive1(...);
- > else
- > recursive1(a, ...);
- > }
-
- You can't get there from here. Best you could do, and this isn't really
- very safe at all, is:
-
- void rhelper(va_list ap)
- {
- va_list asave = ap;
-
- int a = va_arg(ap,int);
-
- if (a == 0)
- rhelper(ap);
- else
- rhelper(asave);
- }
-
- void recursive1(int a, ...)
- {
- rhelper((va_list)&a);
- }
-
- Please, folks, no flames. I merely suggest how he can accomplish his
- objective, I do _not_ recommend the practice, nor do I claim it will
- even work on all architectures.
-
-
- alane@wozzle.linet.org (J. Alan Eldridge)
- Fido: The University of Walamaloo 1:272/38.473
-