0Pricing
C Academy · Lesson

Conditional Compilation

ifdef and macros.

The Preprocessor

Before the compiler ever sees your code, the preprocessor runs. It handles every line starting with #: includes, macros, and conditionals.

Conditional compilation lets you include or exclude blocks of code based on conditions evaluated at this stage, producing different builds from one source.

Defining Macros

#define creates a macro. With no value it is just a flag you can test later.

Object-like macros replace a name with text; flags simply mark that something is set.

#define MAX_USERS 100   /* value macro */
#define DEBUG          /* flag macro */

All lessons in this course

  1. Conditional Compilation
  2. Multi-File Projects
  3. Makefiles
  4. Static and Shared Libraries
← Back to C Academy