Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!sri-spam!rutgers!gatech!rebel!didsgn!allan From: allan@didsgn.UUCP (allan) Newsgroups: comp.lang.c Subject: Re: How can I use #define to make something completely disappear? Message-ID: <109@didsgn.UUCP> Date: Mon, 2-Nov-87 10:30:29 EST Article-I.D.: didsgn.109 Posted: Mon Nov 2 10:30:29 1987 Date-Received: Sat, 7-Nov-87 06:40:22 EST References: <10083@brl-adm.ARPA> Organization: Digital Design Inc., Atlanta, GA USA. Lines: 45 In article <10083@brl-adm.ARPA>, ultra!wayne@ames.arpa (Wayne Hathaway) writes: > 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); > One thing that I have used in various C programs is the following: #ifdef DO_DEBUG #define DEBUG(x) x #else #define DEBUG(x) #endif then use the debugging lines as follows: if ( overt_error ) { DEBUG(printf("Danger Will Robinson! %d %d %d\n", 1,2,3)) ; do_recovery() ; } or whatever form you need. The only drawback from this form is that the "DEBUG" statement must be on only one line as it is the preprocessor that does this work and macros must be contained on one line (or should I say "logical" line?). The above form is also nice as programs can be compiled in "DEBUG" mode from the command line. For example: cc myprog -DDO_DEBUG Also, this will work with "if"s as the semi-colon is outside of the DEBUG macro. Thus, if ( d_flag ) DEBUG(printf("Doing debug stuff\n")); else printf("It works!"); works. I hope this is helpful for you. -Allan G. Schrum usenet: ..!gatech!rebel!didsgn!allan