0

let's assume this variadic function is printing nice logs (without knowing its implementation because we don't care)

int printLog(int bla, int foo, const char *format, ...);

in the following code how do I affect the arguments?

void myFunction(int param)
{
    typedef int (*myPrint) (const char *, ...);
    if(param > 0)
    {
         myPrint = printLog; //how do I pass half of the argument here?
    }
    else
    {
         myPrint = printLog(1,2,...); //this is what I would like
    }

   //then use it
   myPrint("Hello World");
   unsigned int blah=1;
   myPrint("blah is %d",blah);
}
2
  • 1
    Simple answer is: You can't. If there is a va_list variant of printLog then you could create a proper myPrint function that passes the correct arguments to printLog. Otherwise you might possibly solve it by using vararg function-like macros. Commented Feb 5, 2020 at 9:18
  • This is called currying. Commented Feb 5, 2020 at 11:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.