Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!samsung!zaphod.mps.ohio-state.edu!think!snorkelwacker!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.lang.c Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <1990May3.234339.6582@athena.mit.edu> Date: 3 May 90 23:43:39 GMT References: <1717@engage.enet.dec.com> Sender: news@athena.mit.edu (News system) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 39 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 ); |> } 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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710