Path: utzoo!censor!comspec!humvax!becker!geac!jtsv16!uunet!snorkelwacker!apple!vsi1!wyse!mips!ultra!wayne From: wayne@ultra.com (Wayne Hathaway) Newsgroups: comp.lang.c Subject: Re: #define DEBUG... (using printf for debugging) Summary: careful of them if/else matchings! Message-ID: <1990May4.212815.11565@ultra.com> Date: 4 May 90 21:28:15 GMT References: <11290@hoptoad.uucp> <40628@cornell.UUCP> <7377@crdgw1.crd.ge.com> <1990May4.161910.1353@cs.columbia.edu> Reply-To: wayne@ultra.com (Wayne Hathaway) Distribution: usa Organization: Ultra Network Technologies Lines: 36 travis@cs.columbia.edu (Travis Lee Winfrey) suggests: # ifdef DEBUG # define dprintf(dlevel,printfargs) if (dlevel <= DEBUG ) \ printf printfargs # else /* DEBUG */ # define dprintf(a,b) # endif /* DEBUG */ A good idea, and one which I also use (slightly more generalized, of course; I just can't resist getting too damn fancy for my own good!). I do have one nit, though: I would suggest defining "dprintf" as: define dprintf(dlevel,printfargs) if (dlevel > DEBUG) ; \ else printf printfargs Why? Consider the following: if ( ) dprintf(1, ("oh no! just had some strange situation\n")); else ; You see, I just HATE programs that stop working when you turn on the DEBUG flag! :-) wayne Wayne Hathaway Ultra Network Technologies domain: wayne@Ultra.COM 101 Daggett Drive Internet: ultra!wayne@Ames.ARC.NASA.GOV San Jose, CA 95134 uucp: ...!ames!ultra!wayne 408-922-0100