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
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

// Q:  But can I make all print_int_expression(…) calls go away just before I submit????
// A:  Make a dummy #define macro where the RHS (right-hand side, replacement text) is empty.

// Q:  Can we control whether print_int_expression(…) is in effect, without modifying our code?
// A:  Build with…
//     $ gcc  u.c  -o u  -D I_AM_DEBUGGING
//                          └────────────┘
//                          Equivalent to putting #define I_AM_DEBUGGING at top of every file
//
//#define I_AM_DEBUGGING

#ifdef I_AM_DEBUGGING

#define print_int_expression(n) ( printf("%s == %d\n", (#n), (n)) )

#else

// Dummy macro:  This will make every call to print_int_expression(…) disappear, leaving only
// the trailing semicolon.
#define print_int_expression(n)

#endif


int main(int argc, char* argv[]) {
    print_int_expression(3 + 5);  // prints:  3 + 5 == 8
    // Since I_AM_DEBUGGING is not defined, this line (↑) will be reduced to just:
                               ;  // Only the semicolon will remain.
    
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

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