varargs question: va_list in structure

R

Rick Anderson

I want to store a "va_list" in a structure (which gets passed around
from function to function). I cannot use the va_copy() routine
to create a copy of the varargs (it looks like it uses stack memory).

Has anyone written some portable code to create a copy of the varargs
information, and subsequent routines to retrieve the varargs information?

Thanks in advance!
Rick
 
R

Richard Bos

Rick Anderson said:
I want to store a "va_list" in a structure (which gets passed around
from function to function). I cannot use the va_copy() routine
to create a copy of the varargs (it looks like it uses stack memory).

Has anyone written some portable code to create a copy of the varargs
information,

Yes; it's called va_copy().

Otherwise, the contents of a va_list are entirely system-dependent. The
Standard says nothing about its layout; all it specifies is how one may
be used.

Richard
 
D

Dave Thompson

I want to store a "va_list" in a structure (which gets passed around
from function to function). I cannot use the va_copy() routine
to create a copy of the varargs (it looks like it uses stack memory).
What do you mean 'looks like'? Do you just mean the syntax looks like
a function call? It needn't be, and IME never is. Each of the
va_list's will certainly occupy space, but if you want to have them
there's no way around that.
Has anyone written some portable code to create a copy of the varargs
information, and subsequent routines to retrieve the varargs information?
va_list is permitted to be location dependent in an unspecified
fashion = dependent on the implementation and undocumented, so no one
could possibly write fully Standard code to do this. That's why
va_copy exists.

On all implementations I know of either a bitwise copy with memcpy
(for array) or an assignment (otherwise) works. But any implementation
where va_copy is provided and does something which is less efficient
than (whichever of) those, is so badly done I wouldn't trust it for
int main ( void ) { return 0; }

Or, do you actually need to copy? Can you just va_start the one in
your structure to start with?

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top