Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!sq!msb From: msb@sq.UUCP Newsgroups: comp.lang.c Subject: Re: How can I use #define to make something completely disappear? Message-ID: <1987Nov6.132634.20906@sq.uucp> Date: Fri, 6-Nov-87 13:26:34 EST Article-I.D.: sq.1987Nov6.132634.20906 Posted: Fri Nov 6 13:26:34 1987 Date-Received: Sun, 8-Nov-87 08:39:08 EST References: <10083@brl-adm.ARPA> <850@tut.cis.ohio-state.edu> <9187@mimsy.UUCP> Reply-To: msb@sq.UUCP (Mark Brader) Organization: SoftQuad Inc., Toronto Lines: 26 Checksum: 43939 Chris Torek (chris@mimsy.UUCP) suggests: > #define DBPRINT(arglist) if (dflag == 0) /* void */; else printf arglist As he says, this form lets the macro work correctly inside if-statements. Personally, though, I prefer to make my macros expression-like no matter how complicated it makes them; then I know that what looks like an expression statement really is an expression statement, and again they work anywhere. The above can in fact be written about as simply in expression style, as either of: #define DBPRINT(arglist) (dflag && printf arglist) #define DBPRINT(arglist) (dflag? printf arglist: 0) or other stylistic variations that I don't need to enumerate (and neither do you, probably). Of the three forms in this message, I strongly prefer the last, as it is the only one that expresses the ifness in the conventional sense (as it would normally be said outside a macro in C). "Avoid null THEN" -- Kernighan and Plauger Mark Brader, SoftQuad Inc., Toronto, utzoo!sq!msb, msb@sq.com