473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

stdafx.h - what's it all about?

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==]
Nov 17 '05 #1
3 1789
stdafx.h includes all kinds of defines and includes to other files. It's
needed wherever those files are needed. Mostly it includes all of the afx
support stuff, thus the name stdafx.h.

Tom

"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==]

Nov 17 '05 #2
Peter Oliphant wrote:
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==]

You don't have to use PCH, you can always set the "Dont Use PreCompiled
Headers" option in VC.net.

--
Rob Schieber
Nov 17 '05 #3
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==]

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Darren | last post by:
I just want do some console C++ programs. Do I still need this wield header"stdafx.h"? Thanks
2
by: Tommy Vercetti | last post by:
All C++ files in VC++ must start with #include "stdafx.h" Did anyone ever figure out why? Other C++ compilers have precompiler mechanisms that don't need source code modifications to function....
3
by: Egbert Nierop \(MVP for IIS\) | last post by:
Thanks in advance for answering this question.
7
by: silversurfer | last post by:
Hello world, I am using linux and os x and tried to compile some c++ sources (dealing with image processin). Although many people wrote that the code worked at theirs, I got the error that the...
2
by: Lloyd Dupont | last post by:
Do you have any link about StdAfx? Apparently anything which written before #include "StdAfx.h" is ignored! Why the default empty project created by the wizard put it in to the .cpp file...
16
by: Chris Shearer Cooper | last post by:
In our Visual Studio 2005 application, we have several of our application's H files that are #included into stdafx.h. What is odd, is that when we change those application H files, VS2005...
2
by: Bob Altman | last post by:
Ok, I've wondered about this for a long time: Where does the name "StdAfx" come from? TIA - Bob
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.