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.