When including ".h" (header files) into a program, does the file have to be in a relative directory to the file that is calling it? And if so, what is the difference from using "somefile.h" to <somefile>?
thanks.
When including ".h" (header files) into a program, does the file have to be in a relative directory to the file that is calling it? And if so, what is the difference from using "somefile.h" to <somefile>?
thanks.
<somefile.h> includes from the compiler include directories.
"somefile.h" includes from the relative directory to the file that is calling it.
"The Internet treats censorship as damage and routes around it." - John Gilmore
Not necessary. In the project you can specify several include directories that compiler will search for include files... It's a good practice to distinct standard includes from project file includes using <> and "" syntax<somefile.h> includes from the compiler include directories.
"somefile.h" includes from the relative directory to the file that is calling it.
Update
Here is what msdn says:
Syntax Form Action
Quoted form
This form instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of any files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable.
Angle-bracket form
This form instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then, when compiling from the command line, along the path specified by the INCLUDE environment variable.
Last edited by vart; 10-28-2006 at 11:01 AM.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
And here's what the standard says:
In other words, nothing much. In theory, every compiler is free to do whatever it wants, as long as it documents it.Code:2 A preprocessing directive of the form # include <h-char-sequence> new-line searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined. 3 A preprocessing directive of the form # include "q-char-sequence" new-line causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delim- iters. The named source file is searched for in an implementation- defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read # include <h-char-sequence> new-line with the identical contained sequence (including > characters, if any) from the original directive.
MS's documentation pretty much is the established convention, except that it is redundant: the quoted form could omit the part about /I and INCLUDE, because the standard says that if the method of the quoted form fails, the method of the angle-bracket form must be tried.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law