I think I posted a question similar to this on here a while back but I
can't find the thread and I need something more general anyway.
My problem is I have 2 variadic functions , one of which needs to call
the other passing its entire argument list but the other needs to be
callable from anywhere else in the program as a variadic too, ie it
*can't* have va_list as a paramater type.
eg:
void func1(char *fmt, ...)
{
prepend something to format
func2(fmt,args);
}
void func2(char *fmt,...)
{
}
Is this possible? Nothing I try seems to work.
Thanks for any help
B2003
>My problem is I have 2 variadic functions , one of which needs to call
>the other passing its entire argument list but the other needs to be
>callable from anywhere else in the program as a variadic too, ie it
>*can't* have va_list as a paramater type.
Have two versions of each function: one with a va_list argument and
a variadic one which just calls the other one. Then calls between
them can just use the va_list version.
The *printf() functions follow this pattern - fprintf(), vfprintf(),
fscanf(), vfscanf() etc.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
>My problem is I have 2 variadic functions , one of which needs to call
>the other passing its entire argument list but the other needs to be
>callable from anywhere else in the program as a variadic too, ie it
>*can't* have va_list as a paramater type.
>
>eg:
>
>void func1(char *fmt, ...)
>{
> prepend something to format
> func2(fmt,args);
>}
>
>
>
>void func2(char *fmt,...)
>{
>
>}
How about if you provide variadic interfaces for your func1() and
func2(), and wrap the stuff that was in func2() into a new func3()
which can accept a va_list.
#include <stdio.h>
#include <stdarg.h>
void func1(char *fmt, ...)
{
/* prepend something to fmt, giving newfmt */
va_list args;
va_start (args, fmt);
func3 (newfmt, args);
va_end (args);
}
void func2(char *fmt, ...)
{
/* leave fmt unchanged */
va_list args;
va_start (args, fmt);
func3 (fmt, args);
va_end (args);
}
void func3(char *fmt, va_list arglist)
{
/* do stuff with fmt and arglist - probably like this: */
vfprintf(stderr, fmt, arglist);
}
I'm doing something similar to this - albeit in C++ - with a debug
logging class, where my equivalent of func3 is private, and I provide
a number of public interfaces which are variadic.
--
PGP key ID 0xEB7180EC
Hi,
Apart from refactoring your code to work with variadics, you can
look for compiler extensions which might help. GNU c compiler for
example, has __builtin_apply_args()
Just a thought...
Best regards,
Pranav
--------------------------------------------------------------------------
Software gets slower faster than hardware gets faster. - Niklaus Wirth
> I think I posted a question similar to this on here a while back but I
> can't find the thread and I need something more general anyway.
>
> My problem is I have 2 variadic functions , one of which needs to call
> the other passing its entire argument list but the other needs to be
> callable from anywhere else in the program as a variadic too, ie it
> *can't* have va_list as a paramater type.
Introduce a third function with a va_list arg that both variadic functions
call.
--
Chris "sharing is all" Dollin
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England