Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 777 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the difference between #include <filename> and #include "filename"?

#1
What is the difference between using angle brackets and quotes in an `include` directive?

- `#include <filename>`
- `#include "filename"`
Reply

#2
An #include with angle brackets will search an "implementation-dependent list of places" (which is a very complicated way of saying "system headers") for the file to be included.

An #include with quotes will just search for a file (and, "in an implementation-dependent manner", bleh). Which means, in normal English, it will try to apply the path/filename that you toss at it and will not prepend a system path or tamper with it otherwise.

Also, if #include "" fails, it is re-read as #include <> by the standard.

The <a href="http://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html">gcc documentation</a> has a (compiler specific) description which although being specific to gcc and not the standard, is a lot easier to understand than the attorney-style talk of the ISO standards.
Reply

#3
At least for GCC version <= 3.0, the angle-bracket form does not generate a dependency between the included file and the including one.

So if you want to generate dependency rules (using the GCC -M option for exemple), you must use the quoted form for the files that should be included in the dependency tree.

(See

[To see links please register here]

)
Reply

#4
The sequence of characters between < and > uniquely refer to a header, which isn't necessarily a file. Implementations are pretty much free to use the character sequence as they wish. (Mostly, however, just treat it as a file name and do a search in the *include path*, as the other posts state.)

If the `#include "file"` form is used, the implementation first looks for a file of the given name, if supported. If not (supported), or if the search fails, the implementation behaves as though the other (`#include <file>`) form was used.

Also, a third form exists and is used when the `#include` directive doesn't match either of the forms above. In this form, some basic preprocessing (such as macro expansion) is done on the "operands" of the `#include` directive, and the result is expected to match one of the two other forms.
Reply

#5
The `#include <filename>` is used when a system file is being referred to. That is a header file that can be found at system default locations like `/usr/include` or `/usr/local/include`. For your own files that needs to be included in another program you have to use the `#include "filename"` syntax.
Reply

#6
The `<file>` include tells the preprocessor to search in `-I` directories and in predefined directories **first**, then in the .c file's directory. The `"file"` include tells the preprocessor to search the source file's directory **first**, and then revert to `-I` and predefined. All destinations are searched anyway, only the order of search is different.

The 2011 standard mostly discusses the include files in "16.2 Source file inclusion".

> 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 " 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.

Note that `"xxx"` form degrades to `<xxx>` form if the file is not found. The rest is implementation-defined.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through