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

Jonathan I. Kamens jik at athena.mit.edu
Fri May 4 09:43:39 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 );
|> }

  Because it's sloppy and causes good compilers to complain.  Compiling
your program on an IBM RT/PC running AOS4.3 with MetaWare's High C
compiler (version 2.1y) works, but produces the following warnings:

    w "foo.c",L5/C8:        "What the <%s> is going on?\n"
    |    Expression has no side-effects.
    w "foo.c",L5/C8:        Expression has no side-effects.

It's stupid to write code that makes the compiler bitch when it's
possible to accomplish the same purpose without the compiler complaining
at all.  The more a compiler is forced to bitch, the more programmers
come to expect compiler error messages, and therefore the less seriously
they take them.

  I personally make it a policy never to write any "real" code (i.e.
code that I expect anyone else to ever see; and please let's not get
into the debate of one-time-only programs again) that won't compile with
High C without any errors.  I wish more programmers had better compilers
to check their code with, and/or ran their code through lint more often,
because it's a rare program I get off the net that doesn't cause
compiler errors or warnings when I compiler it on my system.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.lang.c mailing list