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

Jeffrey Adam Gordon gordon at mimir.cs.cornell.edu
Fri May 4 00:50:35 AEST 1990


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

But its a pain to have to type the #ifdef ... #endif all the time, and
its less readable than simply having:

	DEBUG ("debugging information");

Now, I can use the latter format if I

#define DEBUG printf

but then how do I turn DEBUG off?


I have though of doing the following (which is not very elegant but I
thought it would work):

#ifdef DODEBUG
#   define DEBUG printf
#   define ENDDEBUG ;
#else
#   define DEBUG /*
#   define ENDDEBUG */
#endif DODEBUG


which would allow the following syntax for debugging

	DEBUG ("the value is %d", val); ENDDEBUG

Unfortunately, I can't figure out how to #define something to be equal
to "/*" sinece "/*" always seems to be interpreted as the start of a
comment.

Well, I've been rambling trying to describe the problem.  Basically,
does anyone have an idea how I can do the above easily and elegantly?

Thanks for reading.

- Jeff
	



More information about the Alt.sources mailing list