Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we use `#include "stdafx.h"` instead of `#include <stdafx.h>`?

From here, it is said that:

For #include "filename" the preprocessor searches in the same directory as the file containing the directive. This method is normally used to include programmer-defined header files.

For #include <filename> the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files.

While this wiki link suggests that stdafx.h is an header file pre-designed by visual studio IDE

stdafx.h is a file, generated by Microsoft Visual Studio IDE wizards, that describes both standard system and project specific include files that are used frequently but hardly ever change.

Compatible compilers (for example, Visual C++ 6.0 and newer) will precompile this file to reduce overall compile times. Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.

The AFX in stdafx.h stands for Application Framework eXtensions. AFX was the original abbreviation for the Microsoft Foundation Classes (MFC). While the name stdafx.h is used by default, projects may specify an alternative name.

Then

Why do we use #include "stdafx.h" instead of #include <stdafx.h> ?

like image 251
Sepideh Abadpour Avatar asked May 16 '16 15:05

Sepideh Abadpour


People also ask

Why shouldou use WWW for your website?

ou should use www because today you have a small web site, and tomorrow you want a big web site. Really big.

What is the technical reason to use WWW in a URL?

The technical reasons to use www primarily apply to the largest web sites which receive millions (or more) of page views per day, web sites with a large number of services across several subdomains, and virtually any web site hosted in “the cloud” by an application service provider. Go here www. is not deprecated for more info.

What is Linux and why should you care?

Since Linux is open source, many Linux enthusiasts have signed up as developers of the operating system. In most cases, they do this for free because of their love of the system. This team is constantly working to keep Linux a cutting-edge and secure operating system. Bugs get documented and resolved quickly.


2 Answers

A stdafx.h, stdafx.cpp pair is generated by VS from a template. It resides in the same directory the rest of the files end up. You will probably end up altering it specifically for your project. So we use "" instead of <> for exactly the reason that it's in the same directory as your first quote describes.

like image 155
Edward Strange Avatar answered Nov 15 '22 16:11

Edward Strange


Because stdafx.h is different for each project. As you quoted, #include "" searches the path of the current project, and this is where stdafx.h is located.

Using #include <stdafx.h> would be a huge mistake, because it would have to be in the library path (where all the standard library headers are located). This would mean that you shouldn't modify it, or that it always stays the same, but it's never the same for different projects.

So even though it is generated by Visual Studio, it is specific to the project, not to all projects.

like image 27
Rakete1111 Avatar answered Nov 15 '22 15:11

Rakete1111