Conditional Compilation and Conditional Build
摘要
We’ll now consider how to assemble, compile, and build a specific version of a program. The file minmax.c (Listing 6-1) contains code that makes it compile differently based on whether or not the variable C_VERSION is defined at build time. If C_VERSION is defined, lines 12–25 are compiled, otherwise lines 28–29 are compiled. The main() function gets its definition of printMin and printMax based on which section is active. If C_VERSION is defined, min and max are defined as macros, and printMin and printMax are implemented using min and max within the c program. If C_VERSION is not defined, we have only declarations of printMin and printMax. The actual implementation is provided by the linker using minmax.obj at build time.