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

Robin Pickering rob at icarus.inmos.co.uk
Fri May 4 18:43:40 AEST 1990


In article <1717 at engage.enet.dec.com> wallace at oldtmr.enet.dec.com (Ray Wallace) writes:
>
>Why not just do this -
>
>#define	BITCH				/* IE: don't print it */
>#define	DEBUG printf			/* IE: do print it */
>main( )
>{
>  BITCH( "What the <%s> is going on?\n", "hell" );
>  DEBUG( "%d - nothing.\n%d - something.\n", 1, 2 );
>}

The trouble with this approach is that the debug strings and the cost of
evaluating the expr, still get compiled in whether debug is on or not.
This may not be a problem in some applications, but if you don't mind the
debug information always being in the code then why not turn it on at runtime
by making DEBUG a function whose operation is controlled by a runtime switch
(much more flexible and at least there is the possibilty of making those
 compiled in strings work for a living occaisionally).

If you do use the above approach, might I suggest:
#define BITCH (void)   /* IE: do nothing, but dont make lint scream about
                          each debug line */


 Rob Pickering.
--
JANET:     ROB at UK.CO.INMOS                      | Snail: 1000 Aztec West
Internet:  rob at inmos.com                        |        Almondsbury
Path:      ukc!inmos!rob or uunet!inmos-c!rob   |        Bristol BS12 4SQ
Phone:     +44 454 611638                       |        UK



More information about the Comp.lang.c mailing list