Skip to content
Latchkey

What Is a Header Guard?

A header guard, also called an include guard, is a set of preprocessor directives that wrap a header so its contents are processed only the first time it is included. A unique macro is defined on first inclusion and checked on later ones to skip the body. This stops the same declarations from appearing twice in one translation unit.

Why it matters

Without a guard, a header pulled in through multiple include paths produces redefinition errors that break the build. Header guards are a basic safeguard for any nontrivial header.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →