LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

What does the C preprocessor do?

The preprocessor is a text-substitution pass that runs first, handling every directive starting with # before the real compiler ever sees the code.

It knows nothing about C's meaning — it just edits text. Its main jobs:

  • #include — paste a header file's contents in place
  • #define — substitute macros and named constants
  • #ifdef / #ifndef — conditionally keep or drop code
  • #pragma — compiler-specific directives
#include <stdio.h>     // pastes stdio.h here
#define MAX 100        // replaces MAX with 100 everywhere
#ifdef DEBUG
    printf("debug\n"); // only compiled when DEBUG is defined
#endif

You can inspect the result with gcc -E program.c.

Classic gotcha: because macros are blind text substitution, not function calls, they bite you on precedence:

#define SQUARE(x) x*x
SQUARE(1+2)   // expands to 1+2*1+2 = 5, NOT 9

The fix is to parenthesise everything: #define SQUARE(x) ((x)*(x)).

Go deeper:

From Quiz: REVE1 / The Processor Interface | Updated: Jul 10, 2026