Conditional Compilation
Abstract
This chapter expands on conditional compilation directives available in the preprocessor. There is an emphasis on how conditional compilation can be used in embedded programs to use a single source code base to produce firmware for multiple products or product versions.
The use of defined() and getenv() in conditional compilation directives is explained, with examples. The use of conditional compilation directives for debugging and diagnostics is also covered. This chapter shows how global defines supported by most compilers can be used.
Examples and exercises are for the popular PIC® microcontroller manufactured by Microchip.
Keywords
Conditional compilation
Preprocessor
if
ifdef
Defined
Get Embedded C Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.