The fundamental difference is in which paths are searched.
You're supposed to use the angle bracket form for "system" includes, and regular quotes for project-local includes.
The fundamental difference is in which paths are searched.
You're supposed to use the angle bracket form for "system" includes, and regular quotes for project-local includes.
Quotes instruct to search first in current directory, then in system directories (either path hardcoded in compiler/preprocessor or specified with -I
). By using angle brackets you opt out of searching the current directory first.
Compiler output definitely does not depend on the quotes because it's handled at the preprocessing stage. Except for the case when due to the altered search behavior different files are being included.
There is no technical difference in general, and everything anyone tells you about it just local style, probably influenced by past compilers - many modern compilers implement the initial search in exactly the same way (often other common behaviors are available via command line option). The standard leaves the behavior in the hands of the implementer, with no particular rationale for supporting both syntaxes.
As per section 6.10.2 of the ISO C99 standard, the search paths for <> and "" are both implementation-defined. The ONLY difference between them in the eyes of the standard is that using "" will fall back on <> if it cannot be resolved. (Don't be tripped up by the standard seeming to make a distinction between "header" and "source file" - there isn't a difference actually defined by the standard other than the fact that some names are reserved - "stdio.h", etc.)
The C language standard says that <>
is to be used for "headers" and ""
is to be used for "source files". Now, don't get all up in arms about the "source files" thing. When the standard says "source files", it doesn't mean what you think. The term "source files" as used in the standard encompasses what we colloquially call "header files" (in addition to what we commonly call "source files").
When the standard talks about "headers", it isn't specifically talking about files at all. The standard does not require headers to exist as files. They could be built-in to the compiler for all the standard cares.
So the real difference between <>
and ""
is that <>
is used for headers and ""
is used for files. If you know that the source you'll be including is a file then you should use ""
.
In practice, compilers use different search algorithms for <>
versus ""
. This is allowed by the standard as the search algorithm to be used for either one is implementation defined. But this is not the real difference as expressed by the standard.
Dan Moulding got it right; unwind, hacker, and Nick Bastin got it wrong. Sorry.
#include <...>
is for headers, which need not even be files in the filesystem, but could e.g. be internal to the compiler.
#include "..."
is for files, and only if no such file can be found, does it default back to #include <...>
.
How and where these headers and files are looked for, and whether < > should be used for system files and " " for project files, which is indeed a common convention, is completely up to the compiler and the project.
The C Standard (ISO/IEC 9899:1999) says (emphasis mine):
6.10.2 Source file inclusion
Constraints
A
#include
directive shall identify a header or source file that can be processed by the implementation.Semantics
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.
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 " delimiters. 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.
Warning: this is pure speculation. I do not have enough experience with the Intel compiler to know if it works this way, nor am I aware of any compiler that does.
If a compiler implements pre-compiled headers, it might use those for one form of include but not the other. If the pre-compiled header gets out of sync with the actual header, you would get different results depending on which was included.
For gcc compiler there is difference between <> and "" headers. If <> header is included from the directory that's supplied as -isystem to preprocessor, then warnings are not emitted for the header included. With -Werror this makes a huge difference in certain cases.
Intel compiler also does have -isystem directive, so it may be applicable to icc as well.
Let alone the difference in lookup directories that's too obvious to note.
#include <somefile.h>
will check the system include paths (including any additional path's added for a project).
#include "somefile.h"
will check the applications working folder. (i.e. same folder as the source file that has the #include statement in it).