Share via


When to Precompile Source Code

Precompiled code is useful during the development cycle to reduce compilation time, especially if:

  • You always use a large body of code that changes infrequently.

  • Your program comprises multiple modules, all of which use a standard set of include files and the same compilation options. In this case, all include files can be precompiled into one precompiled header.

The first compilation—the one that creates the precompiled header file—takes a bit longer than subsequent compilations. Subsequent compilations can proceed more quickly by including the precompiled code.

You can precompile both C and C++ programs. In C++ programming, it is common practice to separate class interface information into header files. These header files can later be included in programs that use the class. By precompiling these headers, you can reduce the time a program takes to compile.

Note   Although you can use only one precompiled header (.PCH) file per source file, you can use multiple .PCH files in a project.