7.2. Using the printf()-debug method
The printf()-debug method is easy to understand and is still the most common method used to debug applications. To use the method, define the following macro in your codes:
#if !defined(DEBUG) #define DBGMSG(MSGSTR) ((void)0) #else #define DBGMSG(MSGSTR) {\ fprintf(stderr,"In %s() at line %d in file %s: %s"\ , __FUNCTION__, __LINE__, __FILE__, (MSGSTR));\ } #endif
then call this macro where you would like to print messages, for example:
int main(int argc, char *argv[]) { DBGMSG("Hi there!\n"); exit(0); }
If you compile the source code with the -DDEBUG compiler option,then it will print a debug message very similar to the following line:
In main() at line 16 in file printf-debug.c: Hi there!
Although ...
Get Developing and Porting C and C++ Applications on AIX now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.