By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,955 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,955 IT Pros & Developers. It's quick & easy.

varargs question: va_list in structure

P: n/a
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
May 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Rick Anderson <Ri**************@oracle.com> wrote:
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
May 22 '06 #2

P: n/a
On Fri, 19 May 2006 18:41:07 GMT, Rick Anderson
<Ri**************@oracle.com> wrote:
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
May 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.