#define boo(fmt, ...) SomethingToDo(fmt, __VA_ARGS__)
void foo(PCSTR fmt, ...)
{
// some other codes
if(condition1)
{
va_list marker;
va_start(maker, fmt);
// Do something.
va_end(marker);
}
if(somecondition)
boo(fmt, /* I want to put the foo's va_arguments here */);
}
There were many codes which call foo function in my project.
I made a new macro boo today. And I want to call the macro in foo function.
How can I do this?
Edit:
Of course, we can solve this problem to call some functions(Not macro) like StringCbVPrintf.
But I’m finding a way to call a macro.
An answer that was deemed unhelpful
The question was not properly explained. This answer didn’t answer the question that the questioner had in mind, but did answer the question that seemed to be asked. There was a gap between intention and reality.
All facetiousness apart, you call a function or macro with the arguments needed to get your job done. Since you don’t specify what the format should be formatted like, I’ve made up format strings to suit myself – they probably aren’t very usable, but who knows.
Anyway, the key point is that you can call
boo()the macro with different lists of arguments, and those arguments will be conveyed toSomethingToDo().An answer that was deemed more helpful
Given the clarification in the comment, then:
However, for that to work, the underlying function needs to know how to handle a
va_list. That means you normally end up with the following code with a structure similar to the following:This is a ‘standard pattern’ for code that uses variable arguments. You can see it in standard C with:
printf()andvprintf();snprintf()andvsnprintf();fprintf()andvfprintf(); and so on. One version of the function has an ellipsis in the argument list; the other version is prefixed with the letter ‘v’ and takes a ‘va_list’ in place of the ellipsis. The ellipsis code is standardized to four or five lines – more or less as shown; it creates and initializes va_list with va_start, calls the v-function, and returns the result after doing va_end.