Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ames!ucbcad!ucbvax!cbosgd!ihnp4!chinet!rlk From: rlk@chinet.UUCP (Richard Klappal) Newsgroups: comp.lang.c Subject: Re: How can I use #define to make something completely disappear? Message-ID: <1817@chinet.UUCP> Date: Tue, 3-Nov-87 22:57:23 EST Article-I.D.: chinet.1817 Posted: Tue Nov 3 22:57:23 1987 Date-Received: Tue, 10-Nov-87 07:16:36 EST References: <10083@brl-adm.ARPA> Reply-To: rlk@chinet.UUCP (Richard Klappal) Organization: Chinet - Public Access Unix Lines: 70 In article <10083@brl-adm.ARPA> ultra!wayne@ames.arpa (Wayne Hathaway) writes: >Time for my dumb question of the month ... >I have the following sequence many times in a piece of code: > #ifdef DEBUG > printf("XYZ entry, p1=%x, p2=%x\n", p1, p2); > #endif DEBUG >Normal old obvious stuff, right? What I would like to do is replace >all of these sequences with something like: > > DBPRINT("XYZ entry, p1=%x, p2=%x\n", p1, p2); > >and then have one instance of something like: > > #ifdef DEBUG > #define DBPRINT printf > #else > #define DBPRINT > Two ways I can think of: 1) Check back a couple of weeks in the sources archives for Fred Fish's DBUG package. It does exactly what you want, plus a whole lot more. 2) When you edit the file to change the printf(...) to DBPRINT(...) make it as follows: #ifdef DEBUG #define DBPRINT(args) printf args #else #define DBPRINT(args) #endif main() { DBPRINT((x, y, z)); } cc -E ... produces: # 1 "def.c" # 3 "def.c" main() { ; } cc -DDEBUG -E ... produces # 1 "def.c" # 5 "def.c" main() { printf (x, y, z); } The extra set of parens does it. This is adapted from Fred's technique, to give credit where its due. Thanks Fred. -- --- UUCP: ..!ihnp4!chinet!uklpl!rlk || MCIMail: rklappal || Compuserve: 74106,1021 ..!ihnp4!ihu1h!rlk ---