Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!bloom-beacon!eru!luth!sunic!mcsun!ukc!inmos!rob@icarus.inmos.co.uk From: rob@icarus.inmos.co.uk (Robin Pickering) Newsgroups: comp.lang.c Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <6208@ganymede.inmos.co.uk> Date: 4 May 90 08:43:40 GMT References: <1717@engage.enet.dec.com> Sender: news@inmos.co.uk Reply-To: rob@inmos.co.uk (Robin Pickering) Organization: Communications Group, Inmos Limited, Bristol, UK Lines: 31 In article <1717@engage.enet.dec.com> wallace@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@UK.CO.INMOS | Snail: 1000 Aztec West Internet: rob@inmos.com | Almondsbury Path: ukc!inmos!rob or uunet!inmos-c!rob | Bristol BS12 4SQ Phone: +44 454 611638 | UK