MP2: My, oh, my, oh, malloc!
 All Data Structures Files Functions Pages
debug.h
1 #ifdef DEBUG
2 /* Aids printf-style debugging.
3  *
4  * If you rely on printf() extensively for your debugging, DPRINTF()
5  * might be slightly better and can be quickly put to use by simply
6  * "calling" DPRINTF() instead of printf().
7  *
8  * The objectives of DPRINTF() are two-fold:
9  *
10  * 1) Identify with filename, function name, line number the location
11  * of the print statement. This could help if you have many printf()
12  * statements.
13  *
14  * 2) Can be quickly enabled/disabled simply by re-compiling,
15  * _without_ touching the code (e.g., commenting/uncommenting). This
16  * could save time and help minimize the risk of unintentional code
17  * modifications.
18  *
19  * Usage:
20  *
21  * Copy-paste all the lines between (and including) the lines "#ifdef
22  * DEBUG" and "#endif" to the top (or after the "#include"s) of every
23  * .c file where you want to use DPRINTF().
24  *
25  * To use it in your code, just call it as you do printf().
26  *
27  * To enable DPRINTF(), use these two make commands:
28  *
29  * make clean
30  * FLAGS+="-DDEBUG" make
31  *
32  * If you just use "make" without the FLAGS+="-DDEBUG", then DPRINTF()
33  * will not print anything (to be exact, it's as if all the DPRINTF()
34  * calls were commented out).
35  *
36  *
37  *
38  * !! NOTE !!
39  *
40  * This is only for your printf-style debugging. The auto-grader will
41  * NOT enable DEBUG or DPRINTF(). Your MP logic must NOT depend on
42  * DEBUG or DPRINTF().
43  *
44  * This is not thread-safe.
45  *
46 */
47 #define DPRINTF(fmt, ...)
48  fprintf(stderr, "%s(), %s:%d: " fmt,
49  __func__, __FILE__, __LINE__, ##__VA_ARGS__)
50 #else
51 /* no-op */
52 #define DPRINTF(...)
53 #endif