473,699 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable argument lists

Hi,

I have a question about about the use og va_start, va_arg, va_end, ...

I'm trying to pass a variable argument list from one function to
another, but I can't get it to work. My code looks someting like this:

int func_one(char *arg, ...) {
va_list ap;

va_start(ap, arg);
...
/* call func_two with the same arguments as func_one was called */
func_two(arg, ap);
...
va_end(ap);

}

int func_two(char *arg, ...) {
...
}

Can anybody help me with this? Is it possible at all?

/Anders.
Nov 13 '05 #1
3 4739
On 2003-11-16, Anders Andersen <an****@meshtec hnologies.com> wrote:
I'm trying to pass a variable argument list from one function to
another, but I can't get it to work. My code looks someting like this:

int func_one(char *arg, ...) {
va_list ap;

va_start(ap, arg);
...
/* call func_two with the same arguments as func_one was called */
func_two(arg, ap);
...
va_end(ap);

}

int func_two(char *arg, ...) {
...
}

Can anybody help me with this? Is it possible at all?


int func_two(char *arg, va_list ap) {
/* ... */
}

func_two does not need to use va_start/va_end.

-- James
Nov 13 '05 #2
James Hu wrote:
int func_two(char *arg, va_list ap) {
/* ... */
}

func_two does not need to use va_start/va_end.


Actually, it would be an error for it to use them.

--
Hallvard
Nov 13 '05 #3
Anders Andersen wrote:
Hi,

I have a question about about the use og va_start, va_arg, va_end, ...

I'm trying to pass a variable argument list from one function to
another, but I can't get it to work. My code looks someting like this:

int func_one(char *arg, ...) {
va_list ap;

va_start(ap, arg);
...
/* call func_two with the same arguments as func_one was called */
func_two(arg, ap);
...
va_end(ap);

}

int func_two(char *arg, ...) {
...
}

Can anybody help me with this? Is it possible at all?

/Anders.


Yes, but only if you declare func_two as

int func_two(char *arg, va_list ap) {
...
}

You might want to keep the other func_two (with the ...) and
have it call this func_two (with the va_list), but the real
"work" has to be done in the va_list version.

Cheers,

Gabor

Nov 13 '05 #4

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

Similar topics

0
1458
by: Philip Rittenhouse | last post by:
I have discovered a couple of problems with the way the universal gateway code handles optional parameters and variable argument lists in COM servers. It appears to only be a problem when you use the custom interface. What I found was that variable argument lists are not detected at all. Instead they are just converted from SAFEARRAYs to a Python list.
7
6289
by: Kapt. Boogschutter | last post by:
I'm trying to create a function that has at least 1 Argument but can also contain any number of Arguments (except 0 because my function would have no meaning for 0 argument). The arguments passed to the function are strings or must be (automaticly converted to a string e.g. the number 10 should become the string "10". My problem is that I can only find samples and description of printf() like functions where the optional arguments and...
7
8319
by: | last post by:
How to call a function with variable argument list from another function again with variable argument list? Example : double average ( int num, ... ); double AFunct1 ( int num, ... ); double AFunct2 ( int num, ... ); double average ( int num, ... )
3
1632
by: Peteris Krumins | last post by:
Hello, Is it possible to use va lists if i prefare to define functions as following: (won't compile) void die(file, line, fn, fmt, ...) const char *file;
5
1961
by: Jonathan Burd | last post by:
Greetings everyone, I wrote a function to learn about variable-length argument lists. I wonder if there is a better way to detect the end of the argument list than using a sentinel value like the one I am using (NULL in this example) or an argument count parameter (ugh). The following function concatenates a series of C-style strings. I am aware of the fact that not allocating enough memory for `dst` results in UB (gave me a...
3
4279
by: Tomás | last post by:
Let's say we have a variable length argument list function like so: unsigned GetAverage(unsigned a, unsigned b, ...); I wonder does the compiler go through the code looking for invocations of the function, and from there, treat it sort of like a template function? For instance, if we had a template function like so: template<class T> T GetAverage(T a, T b);
9
2784
by: Schraalhans Keukenmeester | last post by:
I have some C functions (with variable length argument lists) that use void pointers as arguments. Is there a way to determine at runtime what type of parameter is actually passed on to the function? PHP and my oldskool turbopascal provide a typeof() function, but my C compiler (gcc 3.4.1) does not seem to provide this function. Perhaps someone crafted a library with some smart code able to inspect the variable passed to a certain...
6
3217
by: CptDondo | last post by:
How do you declare a function with 0 or mroe arguments? I have a bunch of functions like this: void tc_cm(int row, int col); void tc_do(void); void tc_DO(int ln); and I am trying to declare a pointer to them:
9
2582
by: Chad | last post by:
This might be a bit vague and poorly worded..... In my program, I handle function failures using fprintf() and exit() like: fprintf(stderr, "malloc failed"); exit(EXIT_FAILURE); There are 5 of these. Since each one has two lines, the total lines of
19
2128
by: Spiros Bousbouras | last post by:
Every time I've seen an example of a variable argument list function its functionality was to print formatted output. Does anyone have examples where the function is not some variation of printf ?
0
8687
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
8615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
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
9034
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
7750
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
4376
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...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
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
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.