1

The differences between #include <filename> and #include "filename" are compiler implementation specific (What is the difference between #include <filename> and #include "filename"?). GCC's implementation of this is well documented (http://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html). Similar documentation exists for Visual C++.

What are the corresponding rules when compiling with LLVM/Clang? i.e., where does Clang look first and/or not look when using each syntax?

Community
  • 1
  • 1
brandones
  • 1,847
  • 2
  • 18
  • 36

2 Answers2

0

I couldn't find anything in the documentation that specifies the expected behavior in each case, so I was curious and decided to look at the code in here. Might be wrong to assume this is how it will always behave, but without the documentation, I guess the source code is the next best thing.

Searching through the code I found that the #include pragma is processed here in the HandlePragmaDependency method (line 453), where it determines if the include isAngled or not (line 468) and then uses that value as a parameter to the LookupFile() method (line 477).

This method is defined in the HeaderSearch.cpp (line 498) and the documentation comment for it states that:

[...] isAngled indicates whether the file reference is for system #include's or not (i.e. using <> instead of ""). [...]

Later in that method the value for isAngled is used in three places (line 547, 596 and 673) each of which have the following comments.

  // Unless disabled, check to see if the file is in the #includer's
  // directory.  This cannot be based on CurDir, because each includer could be
  // a #include of a subdirectory (#include "foo/bar.h") and a subsequent
  // include of "baz.h" should resolve to "whatever/foo/baz.h".
  // This search is not done for <> headers.
  if (!Includers.empty() && !isAngled && !NoCurDirSearch) {

  ...

  // If this is a system #include, ignore the user #include locs.
  unsigned i = isAngled ? AngledDirIdx : 0;

  ...

  // If we are including a file with a quoted include "foo.h" from inside
  // a header in a framework that is currently being built, and we couldn't
  // resolve "foo.h" any other way, change the include to <Foo/foo.h>, where
  // "Foo" is the name of the framework in which the including header was found.
  if (!Includers.empty() && !isAngled &&
      Filename.find('/') == StringRef::npos) {

Hope it helps.

juan.facorro
  • 9,791
  • 2
  • 33
  • 41
0

Syntax:

#include < filename > (1)

#include "filename" (2)

Explanation

Includes source file, identified by filename, into the current source file at the line immediately after the directive.

1) Searches for the file in an implementation-defined manner. The intent of this syntax is to search for the files under control of the implementation. Typical implementations search only standard include directories. The standard C++ library and the standard C library are implicitly included in these standard include directories. The standard include directories usually can be controlled by the user through compiler options.

2) Searches for the file in an implementation-defined manner. The intent of this syntax is to search for the files that are not controlled by the implementation. Typical implementations first search the directory where the current file resides and, only if the file is not found, search the standard include directories as with (1).

iGian
  • 11,023
  • 3
  • 21
  • 36
  • Please do not plagiarize stuff from [other sources](http://en.cppreference.com/w/cpp/preprocessor/include) and post it as your own answer without giving any credit. This doesn't answer the question anyway since the question asks about a specific compiler while the documentation which you copied from only states what's in the standard. – eesiraed Jun 03 '18 at 20:45