Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!motcid!henley From: henley@motcid.UUCP (Aaron Henley) Newsgroups: comp.lang.c Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <2850@mica6.UUCP> Date: 9 May 90 14:13:02 GMT References: <103kla@physc1.byu.edu> Reply-To: motcid!henley@uunet.uu.net Organization: Motorola Inc., Cellular Infrastructure Div., Arlington Heights, IL Lines: 53 kla@physc1.byu.edu writes: >static int __bug__ = 1; >#define bug(); __bug__ = 1; >#define bugoff(); __bug__ = 0; >#ifdef DEBUG >#define Debug(cmdstr) if(__bug__) { printf cmdstr ; fflush(stdout); } >#else >#define Debug(cmdstr) >#endif >Also, if you get into the source level debugger, and you find that >there may be a problem in another module which was unexpected, you >can turn on its debugging by toggling its __bug__ variable and watching >the output for a while. Looks pretty good, but I would change it a little to like this: #ifdef DEBUG static int __bug__ = 1; #define bug(); __bug__ = 1; #define bugoff(); __bug__ = 0; #define Debug(cmdstr) if(__bug__) { printf cmdstr ; fflush(stdout); } #else #define Debug(cmdstr) #define bug(); #define bugoff(); #endif This way if DEBUG is set off you have no impact at all from the debug statements. Also put this code in a special header file "debug.h" so you can insure that the variables needed are defined properly. Besides your macros Debug, bug, and bugoff hide the functionality of the DEBUG statements so why not hide them all together. -- ___________________________________________________________________ / Aaron Henley, Motorola Inc. DISCLAIMER: std.disclaimer / / Cellular Infrastructure Division UUCP: ...!uunet!motcid!henley / /__________________________________________________________________/