Chapter 4. GCC Command Options 121before it looks for the include file in that directory. The name searched for is the name specified in the#include with .gch appended. If the precompiled header file can’t be used, it is ignored.For instance, if you have #include "all.h", and you have all.h.gch in the same directory asall.h, then the precompiled header file will be used if possible, and the original header will be usedotherwise.Alternatively, you might decide to put the precompiled header file in a directory and use -I to ensurethat directory is searched before (or instead of) the directory containing the original header. Then, ifyou want to check that the precompiled header file is always used, you can put a file of the same nameas the original header in this directory containing an #error command.This also works with -include. So yet another way to use precompiled headers, good for projectsnot designed with precompiled header files in mind, is to simply take most of the header files usedby a project, include them from another header file, precompile that header file, and -include theprecompiled header. If the header files have guards against multiple inclusion, they will be skippedbecause they’ve already been included (in the precompiled header).If you need to precompile the same header file for different languages, targets, or compiler options,you can instead make a directory named like all.h.gch, and put each precompiled header in thedirectory. (It doesn’t matter what you call the files in the directory, every precompiled header in thedirectory will be considered.) The first precompiled header encountered in the directory that is validfor this compilation will be used; they’re searched in no particular order.There are many other possibilities, limited only by your imagination, good sense, and the constraintsof your build system.A precompiled header file can be used only when these conditions apply:• Only one precompiled header can be used in a particular compilation.• A precompiled header can’t be used once the first C token is seen. You can have preprocessordirectives before a precompiled header; you can even include a precompiled header from insideanother header, so long as there are no C tokens before the #include.• The precompiled header file must be produced for the same language as the current compilation.You can’t use a C precompiled header for a C++ compilation.• The precompiled header file must be produced by the same compiler version and configurationas the current compilation is using. The easiest way to guarantee this is to use the same compilerbinary for creating and using precompiled headers.• Any macros defined before the precompiled header (including with -D) must either be defined inthe same way as when the precompiled header was generated, or must not affect the precompiledheader, which usually means that the they don’t appear in the precompiled header at all.• Certain command-line options must be defined in the same way as when the precompiled headerwas generated. At present, it’s not clear which options are safe to change and which are not; thesafest choice is to use exactly the same options when generating and using the precompiled header.For all of these but the last, the compiler will automatically ignore the precompiled header if theconditions aren’t met. For the last item, some option changes will cause the precompiled header to berejected, but not all incompatible option combinations have yet been found.4.21. Running ProtoizeThe program protoize is an optional part of GCC. You can use it to add prototypes to a program,thus converting the program to ISO C in one respect. The companion program unprotoize does thereverse: it removes argument types from any prototypes that are found.