varargs -> varargs mystery

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Sat May 4 07:27:49 AEST 1991


After I posted my inquiry I realized that I was asking a
frequently-asked-question, and the FAQ postings already answered it.  I
cancelled my posting, but not soon enough.

Briefly, the question was:  if A and B are varags functions, how can
one portably write them so that A uses one argument and passes the rest
to B?  The short answer is:  you can't.  The long answer is:  you
cannot.

In <4606 at skye.ed.ac.uk> richard at aiai.ed.ac.uk (Richard Tobin) writes:

     If there were a (portable) way to do what Rahul wanted, those
     functions [such as vfprintf] would be unnecessary.

Right.  The problem is that A wants to use one argument and pass on the
rest to B, but A doesn't know how many arguments there are.  So it
doesn't know how many to pass on to B.

Nonportably, A could fudge with the stack -- if the arguments were
guaranteed to be there -- and pass on most of the stack intact to B.
In assembly language you can probably do this quite easily.  Even in C,
it should be possible to design compilers to allow this and to have
some way of telling the compiler that it should do this.

But nobody did, so there is no portable way of doing it in C.
--
Rahul Dhesi <dhesi at cirrus.COM>
UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.lang.c mailing list