stdafx.h

  • Thread starter Thread starter Tommy Vercetti
  • Start date Start date
T

Tommy Vercetti

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. If the
compiler absolutely has to include that file first, why doesn't it do so
automatically without code modifications?
 
Tommy said:
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. If
the compiler absolutely has to include that file first, why doesn't
it do so automatically without code modifications?

There's no such requirement.

However, projects created by the IDE set the option /Yu'stdafx.h' on all C++
files except stdafx.cpp (which uses /Yc'stdafx.h').. The presense of either
of those options requires that the file have a #include "stdafx.h" somewhere
in it. The compiler simply ignores everything in the file up through that
#include and replaces it with the content of the precompiled header file, so
unless it's the first #include, you're likely to get surprises.

-cd
 
"Carl Daniel [VC++ MVP]"
There's no such requirement.

However, projects created by the IDE set the option /Yu'stdafx.h' on
all C++ files except stdafx.cpp (which uses /Yc'stdafx.h').. The
presense of either of those options requires that the file have a
#include "stdafx.h" somewhere in it. The compiler simply ignores
everything in the file up through that #include and replaces it with
the content of the precompiled header file, so unless it's the first
#include, you're likely to get surprises.

-cd

We could also add that this feature can be enabled or diabled for each
individual source file, in the project properties.


Bo Persson
 
Back
Top