Skip to content

Commit 1d4a0ff

Browse files
committed
debug levels
1 parent 35f0818 commit 1d4a0ff

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

prog.18.3.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33

4-
#define DEBUG(fmt, ...) fprintf (stderr, fmt, __VA_ARGS__)
4+
#ifdef DEBON
5+
# define DEBUG(level, fmt, ...) \
6+
if (Debug >= level) \
7+
fprintf (stderr, fmt, __VA_ARGS__)
8+
#else
9+
# define DEBUG(level, fmt, ...)
10+
#endif
11+
12+
int Debug = 0;
513

614
int process (int i1, int i2)
715
{
816
int val;
917

10-
DEBUG ("process (%i, %i)\n", i1, i2);
18+
DEBUG (1, "process (%i, %i)\n", i1, i2);
1119
val = i1 * i2;
12-
DEBUG ("return %i\n", val);
20+
DEBUG (3, "return %i\n", val);
1321

1422
return val;
1523
}
@@ -20,11 +28,13 @@ int main (int argc, char *argv[])
2028

2129
if ( argc > 1 )
2230
arg1 = atoi (argv[1]);
23-
if ( argc == 3 )
31+
if ( argc > 2 )
2432
arg2 = atoi (argv[2]);
33+
if ( argc == 4 )
34+
Debug = atoi (&argv[3][2]);
2535

26-
DEBUG ("processed %i arguments\n", argc - 1);
27-
DEBUG ("arg1 = %i, arg2 = %i\n", arg1, arg2);
36+
DEBUG (2, "processed %i arguments\n", argc - 1);
37+
DEBUG (2, "arg1 = %i, arg2 = %i\n", arg1, arg2);
2838
printf ("%d\n", process (arg1, arg2));
2939

3040
return 0;

0 commit comments

Comments
 (0)