null stream

26 Nov 2010

I'm outputting debugging messages to the serial port with


....which works fine, but what's the a best way to re-assign debug to a \dev\null sort of stream to discard the output ?



26 Nov 2010

I use macros. I have a function called "debug_printf()" and therefore define a debug header along the lines of this:-

#ifdef DEBUG 
int  debug_printf(const char *format, ...)
#define debug_printf(x, ...)

When DEBUG is not set the macro just replaces to am empty macro that does nothing, otherwise the real function prototype exists and the function is used.