Programming with detailed option in C
3 answers
Just use the (varadic) macro / vararg function that checks the flag before calling something like vfprintf.
/* Crude example. */
void my_log(char *format, ...)
{
va_list args;
if (!ok_to_log)
return;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
EDIT As requested
How about a slightly modified gnu example :
#define eprintf(format, ...) do { \
if (ok_to_print) \
fprintf(stderr, format, ##__VA_ARGS__); \
} while(0)
+9
source to share