I need to wrap a macro so that it can be accessed with a function.
The macro is defined like:
#define gDbgLog(fmt,...) dbgLog(g_pdbg,MODULE_NAME,__FUNCTION__,fmt,##__VA_ARGS__)
void pMonDbgLog(char* fmt, ...)
int x = 51144;
pMonDbgLog("some text %d",x);
DbgLog("some text %d",x);
wrap macro with variable number of arguments
It simply is not possible to "expand" a
valist to a variable number of arguments and pass those to a variadic functions on run-time, at least not with any additional helpers (which are not part of C and are not portable and might not be available for you implementation/platform).
gDbgLog() expects getting each argument passed separately:
gDbgLog("%s %d", "hello, world", 42);
What the code you show does instead is passing exactly one parameter as the
__VA_ARGS__ part, namely the value of
How to solve this?
dbgLog() wraps vsnprintf() to generate the output.
So just drop
gDbgLog() and call
pMonDbgLog() directly passing the
valist as initialised by the code snippet you show.