null stream

26 Nov 2010

I'm outputting debugging messages to the serial port with

 (*debug).printf("foo=%d",foo);

....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 ?

Thanks

Keith

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, ...)
#else
#define debug_printf(x, ...)
#endif

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.