I remember that I have read the following explanation long long time ago:
Here is what happens when you use precompiled headers:
a) When the precompiled header base file (stdafx.cpp) is compiled with /Yc,
the file gets compiled, and once this has happened, the virtual memory of
the compiler process including all internal preprocessor macro tables etc,
is just mapped to a file - the precompiled header file.
b) When a file is compiled with the flag /Yu that tells the compiler, a
precompiled header should be used, the first thing the compiler does now, is
to map the precompiled header containing all internal preprocessor tables
into the virtual memory, instead of initializing them as empty tables and
processing the precompiled header files. This obviously is only possible, if
the #include for the precompiled header is the first thing that happens.
Obviously it is much faster to map a file into memory than to process a
complex header file including many other headers. Exactly that's the purpose
of precompiled headers.
If your precompiled header does nothing, there is no performance benefit,
and you can just turn it off via the project properties.
Hope this helps
Marcus Heege
www.heege.net
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
I know that 'stdafx.h' has to do with pre-compiled headers. However, it
seem weird that it is a required 'include' in any CPP file, especially
since the file itself has no code in it!
I know that 'stdafx.h' is a good place to put "include files that are
used frequently, but are changed infrequently" .
But why does this file HAVE to be included when it contains nothing?
Just curious about this. I just include it like always and therefore this
has not caused any problems... : )
However, its my personal style to put all class code IN the header,
thereby making all such class code in-line. Of course, there are times
this can't be done, like when two classes need to reference each other's
methods or members (i.e., other than just a pointer to an instance of,
say, 'myClass', which can be satisfied via the 'class myClass;' statement
just to let the compiler know that 'myClass' is, indeed, a class that can
be pointed to).
[==P==]