Precompiled Header(s)

M

ma740988

Section 6.5 of Josuttis, C++ Templates states - and I paraphrase.


"Let's assume for the sake of argument that every file to be compiled
starts with the same N lines of code. We could compile these N lines
and save the complete state of the compiler at that point in a so-
called precompiled header. Then, for every file in our program, we
could reload the saved state and start compilation at line N+1."

Josuttis, went on to state that "In practice this measn the files must
start with the same #include directives, which consume a substantial
portion of our build time".

So given a file called 'std.hpp'. For discussion purposes assume
std.hpp contains the following.

# include <iostream>
# include <string>
# include <vector>
# include <deque>
# include <list>

Later: foo.cpp
# include "std.hpp"

template < typename T >
void confused ( const std::vector < T >& bogus ) {
// stuff
} // end confused


At issue: How can I 'save the complete state of the compiler" such
that any / all changes made to confused wont result in re-compilation
of std.hpp?
 
I

Ivan Vecerina

:
: Section 6.5 of Josuttis, C++ Templates states - and I paraphrase.
:
:
: "Let's assume for the sake of argument that every file to be compiled
: starts with the same N lines of code. We could compile these N lines
: and save the complete state of the compiler at that point in a so-
: called precompiled header. Then, for every file in our program, we
: could reload the saved state and start compilation at line N+1."
....
: At issue: How can I 'save the complete state of the compiler" such
: that any / all changes made to confused wont result in re-compilation
: of std.hpp?

Some compilers just happen to implement a precompiled headers feature,
which may be configured/implemented in various ways.

The complier may for example allow you to specify a special compilation
flag for some files that will trigger the generation of precompiled
header data. Other files, with a different compilation flag, are
then configured to use and load a precompiled header information.

This is all compiler-specific. For more specific information, please
check your compiler's documentation, or ask in a forum dedicated
to the compiler/platform you use.

Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top