1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>

// Enable log_int only when LECTURE_DEBUG symbol is defined, either through
// a #define or through a GCC flag.

//#define LECTURE_DEBUG  // OR...  gcc -DLECTURE_DEBUG

#ifdef LECTURE_DEBUG
#   define log_int(x)  printf("%s == %d\n", (#x), (x))
#else
#   define log_int(x)
#endif

// In the macro above, the «#x» argument to printf(…) is expanded to
// the text of the argument passed to log_int.  For example, when calling
// log_int(triple(5)), (#x) will be expanded to "triple(5)", while (x) is
// expanded to the function call triple(5), which evaluates to the value 15.

int triple(int n) {
    return n * 3;
}

int main(int argc, char* argv[]) {
    log_int(triple(5));
    log_int(triple(4));
    log_int(triple(3));
    log_int(triple(2));
    log_int(triple(1));

    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2020 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.