Hi,
I'm trying to achieve a function that does the following:
Code:
void myFunc(const char* str, ...)
{
printf(str, ...);
}
That is, I just want to pass the entire optional parameter list on unmolested. I've read lots about how to unpack the parameters, but I haven't been successful in doing something similar to the above.
--- In more detail ---
I'm using and API that provides a logging function, but uses unsafe string formatting routines, so a single % can cause the program to crash.
So I want to do the following to introduce memory safety, and some #define convienience.
Code:
#ifdef DEBUG
void myFunc(const char* msg, ...)
{
char largeArray[500];
//Notice snprintf is memory safe
snprintf(largeArray, 500, msg, ...); //This, sadly, won't compile
API_logging_function(largeArray);
}
#else
void myFunc(const char* msg, ...) {return;}
#endif
Any help appreciated - and yes, I'm sure there are typo's in the above but I hope my question is clear!
Cheers,
HappyClappers.