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

David H. Thornley thornley at cs.umn.edu
Fri May 4 05:23:47 AEST 1990


In article <40628 at cornell.UUCP> gordon at cs.cornell.edu (Jeffrey  Adam Gordon) writes:
>I want to have a DEBUG flag which controls whether diagnostic printfs
>are executed or not.
>
>The obvious way to do this is:
>
>#ifdef DEBUG
>	printf ("debugging information");
>#endif DEBUG

How about
#ifdef DEBUG
#define D(X) X
#else
#define D(X)
#endif

and 
D(printf("debugging information\n");)

If DEBUG is defined, anything in D() is used as is; if not, anything in
D() is disregarded.  It seems to work for me.

David Thornley



More information about the Comp.unix.wizards mailing list