Consider the following assumptions about C programming (some of which go too far, I confess):
Putting any variable definitions in a header file is incorrect, because each translation unit creates its own copy of the data. And if it's
extern
and used from more than one place, we get UB. The correct usage is to declare variables in header files and define them in the corresponding implementation files.Macros are bad form and can usually be converted to variables or functions.
Redeclaration of functions is completely legal.
PROVIDED the above is followed, include guards become unnecessary. There is an exception for inline
functions, which have to be defined in the header, but many projects do not use them.
Given all of that, why is the include guard an industry standard? Most IDEs even add them automatically upon file creation.
a.h
includes 5 headers, you don't wanta.h
to be expanded in full again), and of course the power to not include a header included by one you do want, by just#define
ing the guard.#pragma once
because that syntax is easier for me to read and is supported by every compiler I've ever used and likely will continue to be supported.