#define DEBUG... (using printf for debugging)
The Programmer Guy
jkimble at nostromo.austin.ibm.com
Sat May 5 05:48:29 AEST 1990
> [quick DEBUG method within programs]
Here's how I usually do it:
#define DEBUG(l, f, s) if (Debug >= l) fprintf(stderr, f, s)
You will have to have "int Debug;" somewhere, usually as a global.
Now you just change (int)Debug to be whatever you want; I usually
have a command-line option that allows me to specify it in levels (ala
UUCP). For example: program -x9 (Debug will be set to 9, maximum debug)
program -x5 (Debug will be set to 5, medium debug)
program -x1 (Debug will be set to 1, minimum debug)
Your DEBUG statements look like so within the program:
DEBUG(7, "Number of elements within array = %d\n", nmbr);
DEBUG(5, "Pointer a = |%s|\n", a);
etc., etc., etc.,
Caveats:
If you just have an information message and don't want any
data passed, make sure you do something like this:
DEBUG(7, "We're in rmdir()...\n", "");
[note the second set of ""]
The final caveat is that you can only pass one parameter per DEBUG()
statement; therefore if you have multiple variables to print you're
going to have to use more than one DEBUG statement. However, I think
this is the cleanest way to handle this sort of stuff. (But I am sure
we're going to see plenty of other methods coming back from The Net).
Hope this helps!
--Jim Kimble, Phone: 512/823-4479 (work)
Yet Another IBM Contractor UUCP: ibmaus!jkimble at cs.utexas.edu
TCP/IP Development, RISC System/6000, RT++, RS/6000, etc.
IBM Austin, TX
"ALPO is 99 cents a can. That's almost SEVEN dog dollars!"
More information about the Comp.lang.c
mailing list