473,785 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

varargs question: va_list in structure

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
2 4127
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
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.ne t
May 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
16782
by: Douwe | last post by:
I try to build my own version of printf which just passes all arguments to the original printf. As long as I keep it with the single argument version everything is fine. But their is also a version which uses the "..." as the last parameter how can I pass them to the orignal printf ? void myprintf(char *txt, ...) printf(txt, ???????); }
2
11902
by: Ian Partridge | last post by:
Hi, I want to write a varargs function which then passes its parameters to another varargs function. I have RTFFAQ: http://www.eskimo.com/~scs/C-faq/q15.12.html which says that the other function should accept a va_list pointer to do this. However, I can't seem to get this answer working.
9
4982
by: grid | last post by:
Hi, I have a function which takes a variable number of arguments.It then calls va_start macro to initialize the argument list.But here in my case I have a special builtin va_start provided by the compiler which I use for performance gains.Then the variable arguments are passed to another varargs function which then uses a builtin va_arg macro to get the arguments. Iam getting an error from the compiler in the called function when a local...
1
9476
by: skillzero | last post by:
Is there a portable way to pass a va_list as a parameter to another function taking a variable argument list? I have a function that takes a printf-like format string and I'd like to use something like %V to pass in another format string and a va_list to allow nesting. It happens to work on my compiler, but I wasn't sure if it's portable to use va_list's as parameters to a variable argument function because va_list isn't always just a...
1
9069
by: pete m | last post by:
I would like to support stdio functions for an extremely primitive type system, as shown in the attached sample program, using dynamic creation of a va_list. I've tested it on successfully a couple platforms, but what I don't know is whether it's actually a legal program. The function of interest is usnprintf, "union sprintf". (psnprintf is a dummy wrapper for vsnprintf, useful for debugging.)
8
2777
by: Fred | last post by:
I've got following program encapsuled fscanf, however, it doesn't work. I'm sure that the content format in "a.txt" is OK, the content would be correctly read if using fscanf directly, what's wrong with my program? Thanks for help! int vsscanf( FILE* fp, const char *fmt, ... ) { va_list arglist; va_start( arglist, fmt );
5
4668
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
On Jun 3, 3:23 am, Jesse Ziser <d...@spam.diewrote: The relevant paragraph from the Standard is: ---- Begin Quote ---- The type declared is va_list which is an object type suitable for holding information needed by the macros
6
29562
by: antianti | last post by:
Hello, I have a function that has a variable # of arguments of varying types. int foo(short a, ...) { va_list argp va_start(argp, a); ... va_end(argp);
1
5549
by: Chuck Chopp | last post by:
I have some code that is being built on the following: Windows Server 2003, both 32-bit & 64-bit editions Windows Vista, both 32-bit & 64-bit editions Windows Server 2008, both 32-bit & 64-bit editions Build tools: Visual Studio 2008. SLES 10 SP1, both 32-bit & 64 bit editions
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.