18

Possible Duplicate:
what is the difference between #include <filename> and #include “filename”

In both cases there is no error ...Is there any difference between them ?

0

10 Answers 10

13

<stdio.h> searches in standard C library locations, whereas "stdio.h" searches in the current directory as well.

Ideally, you would use <...> for standard C libraries and "..." for libraries that you write and are present in the current directory.

Sign up to request clarification or add additional context in comments.

3 Comments

You mean if my *.c file is not in the directory in which standard C library is present, then there will be error ?
no, because it looks there anyway. And I doubt that your c file is in the standard C folder anyway.
No. If you use "...", the only difference is that your .h file will be searched for in the current directory as well as the standard C library locations.
7

The second version is specified to search first in an implementation defined location, and afterwards if the file is not found, search in the same place as the <...> version, which searches in the paths usually specified by the -I command line option and by built-in include paths (pointing to the location of the standard library and system headers).

Usually, implementations define that location to be relative to the location of the including file.

Comments

3

The <> tell the compiler to look for the file in the libraries' headers and "" tell it to look around among your application's headers.

As for why both of them works for you, maybe your compiler also looks for the filename in the library headers in case it didn't find one among yours.

Comments

3

You use #include when you want to say: "look for a file with this name in the system's include directory". You use #include "doublequoted" when you want to say: "look for a file with this name in my own application's include directory; however, if it can't be found, look in the system's include directory".

Comments

2

#include <something.h> is meant for system headers, while #include "something.h" is for headers of your own program. System headers are searched for in usual system directories (and those included with -I argument), which your headers are searched for in current directory and then the same locations as system headers.

see http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC6

Comments

2

For the compilers I've used, "..." starts looking for the include file in the same directory as the source file that is being compiled, then the include path. Includes with <...> start in the include path, skipping the current die unless it is in the include path.

Comments

2

Normally standard header files are enclosed by < > and other user specific files are specifed with " .

Comments

2

I case of "..." compiler first search the header file in your local directory where your .c file presents

while in case of <...> compiler only search in header file folder

Comments

1

<stdio.h> refers to a header (not a header file)
"stdio.h" refers to a source file.

Headers need not exist phisically in the implementation; the way they are identified is implementation-defined (usually the headers are files on specific directories)

When the directive uses ", the source file is searched in an implementation-defined manner and, if not found, the directive is reprocessed as if it was written with < and > in the first place.

4 Comments

I'm confused by C99's wordings. Does this mean that #include <unistd.h> is not valid because unistd.h is not a header? Or is there another reason that it uses "header" for <...> but "source file" for "..."?
Reading it again, it seems to not say that the standard headers constitute the set of headers exclusively. So there can be implementation defined headers, like posix headers and so on.
@litb: I think unistd.h is a header if the implementation (or in this case the POSIX standard, which the implementation also implements) says it's a header. It's not a standard header, but I don't think the C99 standard forbids implementations from allowing headers other than the standard ones. I can't find anywhere that explicitly permits it either, just the text about the mapping from identifiers to headers being implementation-defined.
I think unistd.h is a header if the implementation says so. The Standard is quiet about the effect of including something not a header. Apparently my implementation defines unistd.h as a header, but doesn't define windows.h ...
0

The difference is that header files made by the developer are enclosed by "". Header files that are already in the system are enclosed with <>. Even the <> headers need the -I directive if the directories that are placed are not in the search path of the compiler.

Bottom line: Your headers with "", system headers with <>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.