Wednesday, May 19, 2010

What is the difference between #include and #include ?file?? or "file"

We have two ways to include files in a project.

The first way is to include with the angled brackets <>. This method of inclusion tells the compiler to look for the file in the predefined default location. This predefined default location is often an INCLUDE environment variable that denotes the path to your include files. For instance, given the INCLUDE variable
INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS;

If the file is not found there, the compiler then checks the S:SOURCEHEADERS directory. If the file is still not found, the compiler checks the current directory.

The second way to include files is include with double quotation marks. This method of inclusion tells the compiler to look for the file in the current directory first, then look for it in the predefined locations you have set up. Using the #include ?file? version of file inclusion and applying it to the preceding example, the compiler first checks the current directory for the
specified file. If the file is not found in the current directory, the C:COMPILERINCLUDE directory is searched. If the file is still not found, the compiler checks the S:SOURCEHEADERS directory.

The #include method of file inclusion is often used to include standard headers such as stdio.h or stdlib.h. This is because these headers are rarely (if ever) modified, and they should always be read from your compiler?s standard include file directory.

The #include ?file? method of file inclusion is often used to include nonstandard header files that you have created for use in your program. This is because these headers are often modified in the current directory, and you will want the compiler to use your newly modified version of the header rather than the older, unmodified version.

#include
This will refer the given file in the standard input and output directory.
but
#include"file"
This will first refers the given file in the current directory if this not found it will refers in the standard input and output directory.

No comments:

Post a Comment