Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!csseq!randy From: randy@csseq.cs.tamu.edu (Randy Hutson) Newsgroups: comp.lang.c Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <5192@helios.TAMU.EDU> Date: 3 May 90 21:15:43 GMT References: <11290@hoptoad.uucp> <40628@cornell.UUCP> Sender: usenet@helios.TAMU.EDU Followup-To: comp.lang.c Organization: Computer Science Department, Texas A&M University Lines: 22 In article <40628@cornell.UUCP> gordon@cs.cornell.edu (Jeffrey Adam Gordon) wri tes: >I want to have a DEBUG flag which controls whether diagnostic printfs >are executed or not. I use something like the following: #ifdef DEBUG #define DPRINTF printf #else #define DPRINTF if(0) printf #endif Now there's no need to put an extra set of parentheses about DPRINTF's arguments. As for any efficiency concerns, no compiler I regularly use (gcc, Sequent cc, and sun cc) generates an explicit comparison to 0. However, they do leave in the dead code (calls to printf) unless the optimizer is invoked, so this method could make your executables larger if your C compiler doesn't have an optimizer which eliminates dead code.