473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to pass varargs arguments to 2nd function?

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);
}

I want to be able to call another function, offering the same
variable list of arguments to it.

int bar(int a, ...)
{
va_list argp
va_start(short, a);
...
va_end(argp);
}

How could such a thing be done?

The function bar does not have to use the ... expression
if not doing so will help.

Thanks.
Jul 27 '08 #1
6 29424
On Sun, 27 Jul 2008 13:58:00 -0700, antianti wrote:
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);
}

I want to be able to call another function, offering the same variable
list of arguments to it.

How could such a thing be done?

The function bar does not have to use the ... expression if not doing so
will help.
You can make bar accept a va_list argument, and have bar use va_arg on
foo's list.

int bar(va_list argp)
{
/* ... */
}

int foo(short a, ...)
{
va_list argp;
va_start(argp, a);
bar(argp);
va_end(argp);
}

Consider taking a look at the vprintf (and related) library functions.
They are specifically there to be called this way as well.
Jul 27 '08 #2
On Jul 27, 4:58*pm, antia...@rocketmail.com wrote:
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);

}

I want to be able to call another function, offering the same
variable list of arguments *to it.

int bar(int a, ...)
{
* *va_list argp
* *va_start(short, a);
*...
* *va_end(argp);

}

How could such a thing be done?

The function bar does not have to use the ... expression
if not doing so will help.

Thanks.
<http://c-faq.com/Question 15.12: <http://c-faq.com/varargs/
handoff.html>

--
Robert Gamble
Jul 27 '08 #3

I tried precisely what was in the FAQ and it didn't work with GNU CC.

Ah well, there is a solution: Pass a pointer to the location in the
stack where the varargs are located.

Jul 28 '08 #4
In article <70**********************************@m73g2000hsh. googlegroups.com>,
<an******@rocketmail.comwrote:
>
I tried precisely what was in the FAQ and it didn't work with GNU CC.

Ah well, there is a solution: Pass a pointer to the location in the
stack where the varargs are located.
Beavis&Butthead: ork, ork, ork. He said "stack"...

Jul 28 '08 #5
an******@rocketmail.com writes:
I tried precisely what was in the FAQ and it didn't work with GNU
CC.
It does for me. Can you post an example of it not working? It is
possible there is a misunderstanding.
Ah well, there is a solution: Pass a pointer to the location in the
stack where the varargs are located.
Yuck. As a famous pig once said: "You're skate'n on thin ice, frog!".

--
Ben.
Jul 28 '08 #6
an******@rocketmail.com wrote:
I tried precisely what was in the FAQ and it didn't work with GNU CC.
Then either gcc has a rather serious bug, or your precision
isn't all it's cracked up to be. Not familiar with you but with
some experience of gcc, I incline toward the latter explanation.
Ah well, there is a solution: Pass a pointer to the location in the
stack where the varargs are located.
Oooog. There may be no such thing as the "worst possible"
solution, because any bad solution can most likely be made worse
by lavish application of additional error. "Worst possible" is
therefore a fictitious notion, something like the undescribable
singularity of a black hole. Our mathematics cannot cope with
the singularity, nor can our linguistic formalisms cope with
"worst possible." Still, we can safely say that your solution
is on the wrong side of the event horizon.

Oooog.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jul 28 '08 #7

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

Similar topics

8
by: Vijay | last post by:
Hi all, Im using gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20) on 64bit linux server im trying to compile following code --------------------sam.cpp--------------------- #include...
41
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by...
5
by: deko | last post by:
I'd like to use a bit of code in the OnOpen event of a report: =rptOpen(Me.ReportName), (Me.Tag) --this doesn't work This does work: Private Sub Report_Open(Cancel As Integer)...
2
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...
9
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...
2
by: Rick Anderson | last post by:
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...
5
by: metaperl.etc | last post by:
The following program does not work if you uncomment #lis = + list(args) Evidently Python is opting for the nullary constructor list() as opposed to the other one which takes a sequence....
5
by: Gene | last post by:
Hello all. Is the initializing assignment below ANSI standard- conforming? Is there a way to have the prefix parameters to ... type checked in such an assignment? E.g. in this case int x in the...
13
by: Tim H | last post by:
Goal: to provide the simplest call-site possible at the cost of upfront hackery. I have a function that essentially takes a variable list of arguments: func(const string &k0, unsigned long...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.