Path: utzoo!attcan!darkover!telly!eci386!jmm From: jmm@eci386.uucp (John Macdonald) Newsgroups: comp.lang.c Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <1990May8.133742.10584@eci386.uucp> Date: 8 May 90 13:37:42 GMT References: <11290@hoptoad.uucp> <40628@cornell.UUCP> <2294@awdprime.UUCP> Reply-To: jmm@eci386.UUCP (John Macdonald) Organization: Elegant Communications Inc., Toronto, Canada Lines: 35 In article <2294@awdprime.UUCP> tif@awdprime.austin.ibm.com.UUCP (/32767) writes: |Most people I know of do | #define DEBUG(xx) printf xx |and then | DEBUG(("the flag is %d\n", flag)); |The whole thing is completely removed with | #define DEBUG(xx) The same sequence has been suggested numerous times in previous messages. The double parentheses in this solution are annoying, and error-prone, and not really required. Try the following instead: #ifdef DEBUG_PRINT_ON # define DEBUG printf #else # define DEBUG(ignore) #endif To insert a DEBUG-conditional printf use: DEBUG( "format", args, ... ); (no double parens or other funny syntax required, it just looks like a function call) If you prefer, you can comment out one of the defines rather than controlling it with an ifdef. -- Algol 60 was an improvment on most | John Macdonald of its successors - C.A.R. Hoare | jmm@eci386