Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap variadic function with unknown types?

I have a function in a lib that takes a message and variadic parameters and print them like printf. for e.g.:

printMe(const char *fmt,...);

I'm trying to wrap this function. I don't know what is the parameters types and count. I've trying to do it like this:

printMeWrapper(const char *message,...)
{
    va_list argptr;
    va_start(argptr, message);
    printMe( message,argptr);
    va_end(argptr);
}

But this only prints the first argument. Any idea on how to do this correctly?

like image 887
talon Avatar asked Jun 29 '26 20:06

talon


1 Answers

You have to create a second printMe function taking a va_list argument, just like there's printf and vprintf:

void printMeVa(const char *fmt, va_list va)
{
    ...
}
like image 162
Some programmer dude Avatar answered Jul 02 '26 13:07

Some programmer dude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!