Tricky Tricks ›› Programming Tricks ›› C Languages Tricks ›› Quick Debugging Statements

Quick Debugging Statements

C Programming Tricks

Quick Debugging Statements:

In the C Preprocessor section, we mentioned that you could turn on and off Debugging statements by using a #define. Expanding on that, it is even more convenient if you write a macro (using the PRINTF() macro from the I/O section):

 
 #ifdef DEBUG
 #define DPRINTF(s) PRINTF(s)
 #else
 #define DPRINTF(s)
 #endif
 
 

Now you can have DPRINTF(("Debugging statement")); for debugging statements! This can be turned on and off using the -DDEBUG gcc flag.

Sitemap : Partners