#define DEBUG... (using printf for debugging)
Travis Lee Winfrey
travis at cs.columbia.edu
Sat May 5 02:19:10 AEST 1990
In article <40628 at cornell.UUCP>,
>gordon at 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 at cs.columbia.edu Usenet: rutgers!columbia!travis
More information about the Comp.unix.wizards
mailing list