Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!yale!bunker!garys From: garys@bunker.UUCP (Gary M. Samuelson) Newsgroups: comp.lang.c Subject: Re: How can I use #define to make something completely disappear? Message-ID: <3037@bunker.UUCP> Date: Thu, 5-Nov-87 09:26:28 EST Article-I.D.: bunker.3037 Posted: Thu Nov 5 09:26:28 1987 Date-Received: Tue, 10-Nov-87 05:34:28 EST References: <10083@brl-adm.ARPA> <850@tut.cis.ohio-state.edu> <9187@mimsy.UUCP> Reply-To: garys@bunker.UUCP (Gary M. Samuelson) Organization: Bunker Ramo, an Olivetti Company, Shelton, Ct Lines: 43 In article <9187@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >I suggest instead > >#define DBPRINT(arglist) if (dflag == 0) /* void */; else printf arglist >so that you can use, e.g., > if (it was minor) > DBPRINT((...)); > else > abort(...); > >without having the `else' wind in up the wrong place. Other possible ways to avoid 'else' problems: if (it was minor) { DBPRINT((...)); } else { abort(...); } I often surround 'then' and 'else' statements with braces, even if there is only one statement there. BUT I do not want to start more discussions on the use or non-use of braces. I already know how to use them the *right* way. :-) Instead, I offer yet another debug macro: #define DBPRINT(arglist) {if (dflag) printf arglist;} Now there will be no problem with else's. Note that this one should be invoked without a trailing semicolon: DBPRINT((...)) Or: #define DBPRINT(arglist) (dflag ? printf arglist : 0 ) Gary Samuelson