#define DEBUG... (using printf for debugging)

Aaron Henley henley at motcid.UUCP
Thu May 10 00:13:02 AEST 1990


kla at physc1.byu.edu writes:

>static int __bug__ = 1;

>#define bug(); __bug__ = 1;
>#define bugoff(); __bug__ = 0;

>#ifdef DEBUG

>#define Debug(cmdstr)  if(__bug__) { printf cmdstr ; fflush(stdout); }

>#else

>#define Debug(cmdstr)

>#endif

>Also, if you get into the source level debugger, and you find that
>there may be a problem in another module which was unexpected, you
>can turn on its debugging by toggling its __bug__ variable and watching
>the output for a while.


Looks pretty good, but I would change it a little to like this:

	#ifdef DEBUG

	static int __bug__ = 1;

	#define bug(); __bug__ = 1;
	#define bugoff(); __bug__ = 0;

	#define Debug(cmdstr)  if(__bug__) { printf cmdstr ; fflush(stdout); }

	#else

	#define Debug(cmdstr)
	#define bug();
	#define bugoff();

	#endif

This way if DEBUG is set off you have no impact at all from the debug
statements.  Also put this code in a special header file "debug.h" so
you can insure that the variables needed are defined properly.  Besides
your macros Debug, bug, and bugoff hide the functionality of the DEBUG
statements so why not hide them all together.

-- 
   ___________________________________________________________________
  /  Aaron Henley, Motorola Inc.      DISCLAIMER: std.disclaimer     /
 / Cellular Infrastructure Division   UUCP: ...!uunet!motcid!henley /
/__________________________________________________________________/



More information about the Comp.lang.c mailing list