Path: chuka.playstation.co.uk!tjs From: tjs@cs.monash.edu.au (Toby Sargeant) Newsgroups: scee.yaroze.beginners Subject: Re: Debugging code Date: 28 Sep 1998 06:10:01 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 56 Message-ID: References: <36060A0C.97E@dma-design.com> <36061BEA.536E8D68@scee.sony.co.uk> <3606303C.869@dma-design.com> <3606A600.C79FE1FE@shell.jps.net> <36075F71.B9689F1F@scee.sony.co.uk> NNTP-Posting-Host: longford.cs.monash.edu.au X-Newsreader: slrn (0.9.4.3 UNIX) On 28 Sep 1998 14:36:46 +1000, Toby Hutton wrote: >James Russell writes: > >> Just as an addendum which I find useful, I define 3 macros like so: >> >> #define DEBUG >> >> #ifdef DEBUG >> #define debugStr(xxx) printf((xxx)) >> #define debugStr2(xxx,yyy) printf((xxx),(yyy)) >> #define debugStr3(xxx,yyy,zzz) printf((xxx),(yyy),(zzz)) >> #else >> #define debugStr(xxx) >> #define debugStr2(xxx,yyy) >> #define debugStr3(xxx,yyy,zzz) >> #endif >> >> Then I can just go: >> >> debugStr2("The value of KillerBananaNum = %d\n",killerBananaNum); > >Or you could use: > >#if defined(DEBUG) >#define dprintf(x) printf x >#else >#define dprintf(x) >#endif > >and use it: > >dprintf(("foo = %d (0x%08x), bar = %d (0x%08x)\n", foo, foo, bar, bar)); > >Note the double parentheses. Means you can have just one macro. or, #ifdef DEBUG #define D(x) printf(x) #else #define D(x) #endif #define AND , then: D("foo"); D("foo%s" AND foo); etc. or you can just preprocess your source with m4, and do it in a sane and rational way. may the authors of the c preprocessor spec be cursed for all eternity for not doing it the rightWay(tm). Toby.