473,394 Members | 1,746 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,394 software developers and data experts.

Reusing variable argument list

Hi,

I might post a stupid question, but i prefer give it a shot, as i tried
several things without any success.

In a function called with a varying number of arguments of varying
types, could it be possible to pass all those arguments to another
function that takes a varying number of arguments (smart use of
va_list?).

A small example:

struct A
{
virtual void doStuff( int a, ... ) { /* do stuff here */ }
};
struct ClassB : public A
{
virtual void doStuff( int a, ... ) { A::doStuff( a /*, ... */ ); } //
<-- what do do here?
};

I first though of two things: assembly, that i'd love to avoid as i
need cross-platform support, and some template stuff, but i couldn t
get it working.

So are those kind of calls possible, and if so how?

Thanks,

David

Jun 2 '06 #1
4 5514
"Kufa" <po*****@gmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...
: In a function called with a varying number of arguments of varying
: types, could it be possible to pass all those arguments to another
: function that takes a varying number of arguments (smart use of
: va_list?).

What you do is pass a va_list parameter to the following function.
Look at the way vprintf is declared.

When you actually need to go through the list of parameters multiple
times, this may work by just copying the va_list instance.
If your platform supports va_copy (introduced in C99), using it
will provide a formally corect solution.

hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Jun 2 '06 #2

Ivan Vecerina wrote:
What you do is pass a va_list parameter to the following function.
Look at the way vprintf is declared.
Thanks i lot. I actually thought about passing va_list as a parameter,
but wasn't sure if nested calls to va_arg could break something on a
platform:

void B::doStuff( int a, va_list args )
{
/* Someone decides to do something on the first parameter */
ProperType obj = va_arg(args);
/* do stuff */
A::doStuff( a, args );
}
When you actually need to go through the list of parameters multiple
times, this may work by just copying the va_list instance.
If your platform supports va_copy (introduced in C99), using it
will provide a formally corect solution.


I'll indeed use va_copy when available, but is it safe to assume the
va_arg wont break anything when va_copy is not available? Or should i
look in all my va_list implementations?

Thanks again for your answer.

Jun 2 '06 #3
"Kufa" <po*****@gmail.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
:
: Ivan Vecerina wrote:
: > What you do is pass a va_list parameter to the following function.
: > Look at the way vprintf is declared.
:
: Thanks i lot. I actually thought about passing va_list as a parameter,
: but wasn't sure if nested calls to va_arg could break something on a
: platform:
:
: void B::doStuff( int a, va_list args )
: {
: /* Someone decides to do something on the first parameter */
: ProperType obj = va_arg(args);

You don't call va_arg again here, you re-use the copy of the
va_list that was initialized by the caller.

: /* do stuff */
: A::doStuff( a, args );
: }
:
: > When you actually need to go through the list of parameters multiple
: > times, this may work by just copying the va_list instance.
: > If your platform supports va_copy (introduced in C99), using it
: > will provide a formally corect solution.
:
: I'll indeed use va_copy when available, but is it safe to assume the
: va_arg wont break anything when va_copy is not available? Or should i
: look in all my va_list implementations?

Copying a va_list "just works" on the 2-3 compilers I have been using.
You'll have to try...

: Thanks again for your answer.

You are most welcome!
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Jun 2 '06 #4
nice! thanks, i ll have a try :)

Jun 2 '06 #5

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

Similar topics

0
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...
2
by: Suzanne Vogel | last post by:
'stdarg.h' defines the 'va_arg' type to use in passing variable numbers of parameters to functions. The example of its use given in the Dinkumware documentation *seems* to imply that the 'va_arg'...
4
by: Jon | last post by:
I have links that open https secondary windows using: window.open(url, windowName); The windowName is always the same but I keep getting new windows. Is it possible for each of the links to...
7
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...
7
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...
8
by: John M. Gabriele | last post by:
I'm putting together a small site using Python and cgi. (I'm pretty new to this, but I've worked a little with JSP/servlets/Java before.) Almost all pages on the site will share some common...
10
by: glenn354 | last post by:
I have a form I would like to use in front of several queries. For example, I want to use frmA but only looking at the records retrieved by qryX. Then I want to use frmA again, but only looking at...
5
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...
19
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...

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.