Include Code Only for Debug Builds
Keep a debug line out of the normal report
The workshop report always needs its repair count. During debugging, a second line can show the value before the public report. #ifdef TRACE keeps the enclosed source only when TRACE is defined; the preprocessor makes that choice before C compilation. Here it is defined so both lines appear.
c
#include <stdio.h>
#define TRACE
int main(void) {
int repairs = 4;
#ifdef TRACE
printf("Debug count: %d\n", repairs);
#endif
printf("Repairs: %d\n", repairs);
return 0;
}
Run the example and check the debug line comes before the report. Without the #define TRACE line, preprocessing would leave only the report print. Even #define TRACE 0 would still count as defined to #ifdef.
An ordinary if selects a path while the program runs; both its branches must still be valid C. #ifdef instead selects source before compilation. With a local C compiler, -DTRACE can supply the macro at build time.