[comp.lang.c] Constructing Variable arguments...

ea08+@andrew.cmu.edu (Eric A. Anderson) (06/22/91)

Is there any portable or at least semi-portable way of constructing a
variable arguments chunk of memory other than via a function call?
I have a great number of variable argument functions, and it might be
useful in the future to be able to dynamically build the arguments
that get passed. (it is set up so that I can pass a pointer to a
varargs list, a va_list *pvar).
Any suggestions?
          -Eric
*********************************************************
"My life is full of additional complications spinning around until
 it makes my head snap off."
           -Unc. Known.
"You are very smart, shut up."
           -In "The Princess Bride"
*********************************************************

steve@taumet.com (Stephen Clamage) (06/22/91)

ea08+@andrew.cmu.edu (Eric A. Anderson) writes:

>Is there any portable or at least semi-portable way of constructing a
>variable arguments chunk of memory other than via a function call?
>I have a great number of variable argument functions, and it might be
>useful in the future to be able to dynamically build the arguments
>that get passed. (it is set up so that I can pass a pointer to a
>varargs list, a va_list *pvar).
>Any suggestions?

You can't make any portable assumptions about type va_alist, not
even that the varargs are in a contiguous chunk of memory (some
might be in registers, for example).

What about just passing an array?  You can malloc() the array at the
calling site, realloc() it if it needs to grow, and pass it to an
ordinary (non-varargs) function.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com