Precompiled header files are binary files that have been generated
from ordinary C header files and that have been preprocessed and
parsed using cpp-precomp. When such a
precompiled header is created, both macros and declarations present
in the corresponding ordinary header file are sorted, resulting in a
faster compile time, a reduced symbol table size, and consequently,
faster lookup. Precompiled header files are given a
.p extension and are produced from ordinary
header files that end with a .h extension. There
is no risk that a precompiled header file will get out of sync with
the .h file, because the compiler checks the
timestamp of the actual header file.
When using precompiled header files, you should not refer to the
.p version of the name, but rather to the
.h version in the #include
directive. If a precompiled version of the header file is available,
it will be used automatically; otherwise, the real header file
(.h) will be used. So, to include
foo.p, you would specify
foo.h. The fact that cc is
using a precompiled header is totally hidden from you.
In addition to checking the timestamp, the preprocessor also checks
whether or not the current context is the same as the context in
which the precompilation was performed. For the precompiled header to
be used, the timestamp would need to indicate that the modification
time of the .p version is more recent than the
.h version, and therefore, that the contexts
must be equivalent. The context is the amalgamation of all defines
(#define) in place at the time you compile a
program. If the defines are different the next time you include the
.h file, cpp-precomp will
regenerate the .p file based on the current set
of defines.
Mac OS X system headers are precompiled. For example,
AppKit.p, Cocoa.p,
mach.p, and other precompiled header files are
stored in /System/Library/Frameworks. You can
create your own precompiled header files using the cc
-precomp compile driver flag. For example, the following
command illustrates this process in its simplest, context-independent
form:
cc -precomp header.h -o header.p
If there is context dependence--for example, some conditional
compilation--the -Dsymbol flag is used. In
this case, the command to build a precompiled header file (with the
FOO symbol defined) would be:
cc -precomp -DFOO header.h -o header.p