Tutorial by Examples

There are a number of guidelines to follow when creating and using header files in a C project: Idemopotence If a header file is included multiple times in a translation unit (TU), it should not break builds. Self-containment If you need the facilities declared in a header file, you sh...
If a particular header file is included more than once in a translation unit (TU), there should not be any compilation problems. This is termed 'idempotence'; your headers should be idempotent. Think how difficult life would be if you had to ensure that #include <stdio.h> was only included ...
Modern headers should be self-contained, which means that a program that needs to use the facilities defined by header.h can include that header (#include "header.h") and not worry about whether other headers need to be included first. Recommendation: Header files should be self-contained...
Headers are a crucial consistency checking mechanism, but they should be as small as possible. In particular, that means that a header should not include other headers just because the implementation file will need the other headers. A header should contain only those headers necessary for a con...
Google's Include What You Use project, or IWYU, ensures source files include all headers used in the code. Suppose a source file source.c includes a header arbitrary.h which in turn coincidentally includes freeloader.h, but the source file also explicitly and independently uses the facilities from ...
The C standard says that there is very little difference between the #include <header.h> and #include "header.h" notations. [#include <header.h>] searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the &l...

Page 1 of 1