Source: https://mokxi.com/learn/path/c-build-and-preprocessor
Updated: 2026-11-20

All paths

# Multi-file C: headers, macros and builds

What happens between Run and the chip: one compile per file, a linker that joins them, headers with guards, macros and their traps, #if, extern and static, and build flags. Ends with one codebase that builds for an Uno and an ESP32-C3.

Arduino Uno R3 Free 7 lessons 5 h 4 chapters 2,115 XP Coding · Intermediate +150 XP

0 of 7 done

Start the course free Many files, one program Lesson plan for teachers

What you will build

## 3 projects, built step by step

7 lessons in 4 chapters, about 5 hours on a simulated Arduino Uno R3. Free, in your browser, every step checked by the simulator.

Chapter 1 project

### Headers and guards

A rover on a grid, split into rover.h and rover.cpp. What #include really pastes, a header read twice and the guard that stops it, and why a function body in a header needs inline.
Open it in the simulator

Chapter 2 project

### Conditional compilation

One sketch, many builds: #if picks which lines the compiler ever sees. Debug lines that cost nothing when off, a version gate, the chip it was built for, and a default you can override.
Open it in the simulator

Chapter 3 project

### Build flags

Every Run hands the compiler a list of switches. Read their fingerprints from inside a sketch: the C++ standard, the chip, the optimizer, exceptions. Then a config header, and the linker throwing away code you never call.
Open it in the simulator

The map

## Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

## Split it up

Compile, link, and the headers that hold the promises.

Open 187 XP

### Many files, one program

What Run really does: preprocess, compile each file on its own, link them into one program. A declaration is a promise, a definition keeps it, and a second file joins the build.

0 of 5 steps

Start What is in it

Project Locked 374 XP

### Headers and guards

A rover on a grid, split into rover.h and rover.cpp. What #include really pastes, a header read twice and the guard that stops it, and why a function body in a header needs inline.

0 of 5 steps

4 questions, graded as you go.

Chapter 2

## The preprocessor

Macros, their traps, and #if.

Locked 236 XP

### Macros and their traps

The preprocessor swaps text and knows nothing about C. A square that forgets its brackets, a maximum that reads a sensor twice, # and do-while(0), and when a function or constexpr does the job better.

0 of 6 steps

Project Locked 472 XP

### Conditional compilation

One sketch, many builds: #if picks which lines the compiler ever sees. Debug lines that cost nothing when off, a version gate, the chip it was built for, and a default you can override.

0 of 6 steps

4 questions, graded as you go.

Chapter 3

## Linking and flags

extern, static, and the switches every build passes.

Locked 187 XP

### extern and static

Who can see a name and how long it lives. A global another file reaches with extern, static at file scope that keeps a name private, and a static local that remembers between calls.

0 of 5 steps

Project Locked 410 XP

### Build flags

Every Run hands the compiler a list of switches. Read their fingerprints from inside a sketch: the C++ standard, the chip, the optimizer, exceptions. Then a config header, and the linker throwing away code you never call.

0 of 5 steps

5 questions, graded as you go.

Chapter 4

## Project

One codebase, two boards.

Locked 249 XP

### Project: one codebase for two boards

A beacon that builds unchanged for the Uno and the ESP32-C3. #if on the chip picks the pins, the sizes and a sum show what really differs, and a board.h keeps every difference in one place.

0 of 7 steps

3 questions, graded as you go.

Syllabus

## Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

### Split it up

- Many files, one program What Run really does: preprocess, compile each file on its own, link them into one program. A declaration is a promise, a definition keeps it, and a second file joins the build.
- Headers and guards A rover on a grid, split into rover.h and rover.cpp. What #include really pastes, a header read twice and the guard that stops it, and why a function body in a header needs inline.

Chapter 2

### The preprocessor

- Macros and their traps The preprocessor swaps text and knows nothing about C. A square that forgets its brackets, a maximum that reads a sensor twice, # and do-while(0), and when a function or constexpr does the job better.
- Conditional compilation One sketch, many builds: #if picks which lines the compiler ever sees. Debug lines that cost nothing when off, a version gate, the chip it was built for, and a default you can override.

Chapter 3

### Linking and flags

- extern and static Who can see a name and how long it lives. A global another file reaches with extern, static at file scope that keeps a name private, and a static local that remembers between calls.
- Build flags Every Run hands the compiler a list of switches. Read their fingerprints from inside a sketch: the C++ standard, the chip, the optimizer, exceptions. Then a config header, and the linker throwing away code you never call.

Chapter 4

### Project

- Project: one codebase for two boards A beacon that builds unchanged for the Uno and the ESP32-C3. #if on the chip picks the pins, the sizes and a sum show what really differs, and a board.h keeps every difference in one place.

Kits

## Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

### Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kit

Questions

## About Multi-file C: headers, macros and builds

Is Multi-file C: headers, macros and builds free?

Yes. All 7 lessons of Multi-file C: headers, macros and builds are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Arduino Uno R3?

No. Every lesson runs on a simulated Arduino Uno R3 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Multi-file C: headers, macros and builds take?

About 5 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Headers and guards, Conditional compilation and Build flags.

Where do I start?

With "Many files, one program", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.
