[metadata]
id = "PRE06-C"
type = "recommendation"
category = "PRE"
number = 6
title = "Enclose header files in an include guard"
description = """
Until the early 1980s, large software development projects had a continual
problem with the inclusion of headers. One group might have produced
agraphics.h, for example, which started by includingio.h. Another group might
have producedkeyboard.h, which also includedio.h. Ifio.hcould not safely be
included several times, arguments would break out about which header should
include it. Sometimes an agreement was reached that each header should include
no other headers, and as a result, some application programs started with dozens
of#includelines, and sometimes they got the ordering wrong or forgot a required
header. All these complications disappeared with the discovery of a simple
technique: each header should#definea symbol that means "I have already been
included." The entire header is then enclosed in an include guard: #ifndef
HEADER_H #define HEADER_H /* ... Contents of <header.h> ... */ #endif /*
HEADER_H */
"""
severity = "Low"
likelihood = "Unlikely"
priority = "P3"
level = "L3"
cert_version = "2016 Edition (Wiki)"
last_modified = "Jun 16, 2025"
[rules.cert_c.PRE06-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/PRE06-C.+Enclose+header+files+in+an+include+guard"