Home c++ C++ Passing va_list to function

C++ Passing va_list to function

Author

Date

Category

Tell me how to implement the function:

int test (...) {printf (...);}

That is, pass the va_list parameters to the next function.


Answer 1, authority 100%

It’s impossible to pass an undefined list of arguments just like that, there is no syntax for this in the language. However, the problem can be worked around as indicated by here : a function whose you transfer control must have a variant that accepts va_list .

For your case, you can use vprintf :

void test (char * format, ...) // there must be at least one argument
{
  va_list args;
  va_start (args, format);
  vprintf (format, args);
  va_end (args);
}

Answer 2, authority 14%

Or by macro:

#define prn (A, ...) printf (A, __ VA_ARGS__)

sometimes it’s easier this way, especially if you need to add additional arguments to VA_ARGS . But nevertheless, learn VA_ * interface .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions