473,489 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

getting and passing variable number of parameters

Hi,
I have to write a function that gets variable number of parameters and
pass them to another function (existing).
The problem is that the prototype of the function I call has ",..." so
I can't just pass it parameters in the format of va_list.

The following code does not work since f2 doesn't take arg_list (the
prototype of f2 is the same as f1's)

void f1(char a ,...)
va_list arg_list;
va_start (arg_list, a);
f2(a,arg_list); <==== f2 doesn't take arg_list
va_end;

any ideas how I can do it?
Thanks,
Michael
co***********@yahoo.com
Nov 14 '05 #1
2 7795
On 25 Dec 2003 03:32:30 -0800, co***********@yahoo.com (Michael Cohen)
wrote in comp.lang.c:
Hi,
I have to write a function that gets variable number of parameters and
pass them to another function (existing).
The problem is that the prototype of the function I call has ",..." so
I can't just pass it parameters in the format of va_list.

The following code does not work since f2 doesn't take arg_list (the
prototype of f2 is the same as f1's)

void f1(char a ,...)
va_list arg_list;
va_start (arg_list, a);
f2(a,arg_list); <==== f2 doesn't take arg_list
va_end;

any ideas how I can do it?
Thanks,
Michael
co***********@yahoo.com


There is no way to do this using standard C. You will need to consult
a compiler-specific group to see if you can hack up some compiler
specific solution.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 14 '05 #2
co***********@yahoo.com (Michael Cohen) wrote...
Hi,
I have to write a function that gets variable number of parameters and
pass them to another function (existing).
The problem is that the prototype of the function I call has ",..." so
I can't just pass it parameters in the format of va_list.


What you are trying to do is not possible using standard C. You have
two options, one of which has already been suggested. The other is
this:

If you have source access to the function accepting variadic arguments
that you would like to call, renaming it and modifying it's prototype
may be a better idea. For example:

void mylog(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
/* ... code ... */
va_end(ap);
}
To make this function callable with variable arguments at runtime from
other functions, you could do something like:

void vmylog(const char *fmt, va_list ap)
{
/* ... code ... */
}

void mylog(const char *fmt, ...)
{
va_list ap;
va_start(ap);
vmylog(fmt, ap);
va_end(ap);
}
You can now simply pass vmylog a va_list when you please. If you have
not got source access to the procedure you wish to call, then you have
to go non-portable, otherwise you are screwed.
David.
Nov 14 '05 #3

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

Similar topics

3
14901
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
4
3009
by: Alfred Taylor | last post by:
I essentially need a countif() function for xsl. Something to where I could do countif(node-set, condition). Rather than try to get too extreme, i decided to just write one for my countif() with...
26
2388
by: Michael McGarry | last post by:
Hi, I am pretty sure this is not possible, but maybe somehow it is. Given a variable, can I tell what type it is at runtime? Michael
17
3567
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int...
1
3098
by: Darsin | last post by:
Hi all, I am a new programmer to C# and i am having a following problem. I want to make a single method which takes a variable length array and display it contents. i have defined the method as:...
8
4393
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
4
2976
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
11
3734
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
10
1856
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle...
0
7142
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
7181
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
7352
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
5445
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,...
1
4875
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...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
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 ...
1
618
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.