home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
1
/
1270
< prev
next >
Wrap
Internet Message Format
|
1990-12-28
|
3KB
From: travis@cs.columbia.edu (Travis Lee Winfrey)
Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc
Subject: Re: #define DEBUG... (using printf for debugging)
Message-ID: <1990May4.161910.1353@cs.columbia.edu>
Date: 4 May 90 16:19:10 GMT
In article <40628@cornell.UUCP>,
>gordon@mimir.cs.cornell.edu (Jeffrey Adam Gordon) writes:
>
> I want to have a DEBUG flag which controls whether diagnostic printfs
> are executed or not.
Well, another variation on the debug macro with two parentheses
is to have a first argument that specifies the current level of
interest. This argument can be compared with whatever you need: a
module-specific #define, a module-specific variable, a global
variable. The two biggest problems with this method are the complaints
from lint about constants appearing in an if-statement, and that some
compilers may not strip out the code when you don't want the output.
A sample follow. Note that the numbers here range from 1 to 4 because
I define DEBUG on a per-module basis. Some other people specify their
interest in debugging information in terms of percentages, i.e., show
me 50% of everything you have in this module. that's not intuitive
for me.
(I'm sorry if anyone else has already described this particular
fillip; I looked through all the messages posted so far, as many of
the previous posters should have done.)
/*
* debugging macros. the dprintf macro takes two arguments, a
* debugging level (1, 2, 3, 4) and a list of ordinary printf
* arguments in parentheses, e.g.,
* dprintf(1, ("proc_kill_module: sys_ptr is NULL!\n"));
*
* debugging levels:
* level 1: ordinary unexpected events which the programmer may want
* to know, but a user will not. all "oh no!" type
* information should be marked with this.
* level 2: more detailed, usually per-module information that
* will a programmer will not want to know *unless* he or
* she is debugging that module.
* Level 3: more detailed than 2, usually per-procedure
* debugging information. debugging statements this
* low-level will be removed once gross errors are
* found and removed.
* Level 4: just a level for demarcating extremely low-level,
* usually inner-loop information. removed as level 3 messages.
*
*/
# ifdef DEBUG
# define dprintf(dlevel,printfargs) if (dlevel <= DEBUG ) \
printf printfargs
# else /* DEBUG */
# define dprintf(a,b)
# endif /* DEBUG */
--
Arpa: travis@cs.columbia.edu Usenet: rutgers!columbia!travis