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.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Conditional Compilation and Conditional Build

  • John Schwartzman

摘要

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.