tags:

views:

207

answers:

10
+1  A: 

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

Abhishek Gupta
+4  A: 

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.

Johannes Schaub - litb
+4  A: 

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

Alan Haggai Alavi
@Alan Haggai Alavi You mean if my *.c file is not in the directory in which standard C library is present, then there will be error ?
Parixit
no, because it looks there anyway. And I doubt that your c file is in the standard C folder anyway.
Alexander Rafferty
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.
Alan Haggai Alavi
+1  A: 

#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

che
+1  A: 

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.

John Percival Hackworth
+1  A: 

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

Paniyar
+2  A: 

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.

Venemo
A: 

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

pmg
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 `"..."`?
Johannes Schaub - litb
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.
Johannes Schaub - litb
@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.
Steve Jessop
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` ...
pmg
A: 

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

cateof
+1  A: 

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

Lie Ryan