A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
Header files get included multiple times in a single translation unit. Module A includes common.h. Module B includes common.h. Your main.c includes both A and B. Without protection, common.h's contents are processed twice. Struct definitions are duplicated. Constants are redeclared. The compiler errors out. Include guards solve this with #ifndef/#define/#endif. The first inclusion defines a sentinel macro. Subsequent inclusions see the macro is defined and skip the body.
#ifndef VECTOR_H#define VECTOR_H#include <stddef.h>typedef struct {double *data;size_t length;size_t capacity;} Vector;int vector_init(Vector *v, size_t cap);void vector_free(Vector *v);int vector_push(Vector *v, double val);#endif
The guard macro name follows the convention: filename in uppercase, dots replaced with underscores, _H suffix. VECTOR_H for vector.h. The name must be unique across the entire project. If two headers use the same guard name, the second one is silently skipped. This is a subtle and infuriating bug. Some projects prefix with the project name: MYPROJECT_VECTOR_H.
#pragma once#include <stddef.h>typedef struct {int x;int y;} Point;Point point_create(int x, int y);
#pragma once tells the compiler to include this file only once per translation unit. It is not part of the C standard. It is supported by GCC, Clang, MSVC, and Intel CC. It is shorter and less error-prone than manual guards. But it is not portable to every compiler, and it can fail with symlinked files or files accessible through multiple paths. For maximum portability, use traditional include guards. For convenience in a known toolchain, #pragma once is fine.
Every header you write gets an include guard. No exceptions. It is two lines of code that prevent a class of build errors. The naming convention matters: unique, descriptive, project-prefixed. Next: #if 0 as a debugging tool for removing code blocks.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.