Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does #include "stdio.h" work? [duplicate]

Tags:

c++

include

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

Why doesn't the compiler complain when I write the following:

#include "stdio.h"

Shouldn't it be

#include <stdio.h>

instead, because stdio.h is actually stored in a library folder and not in the folder of the translation unit? Why does it work anyway?

like image 668
gexicide Avatar asked Dec 03 '12 13:12

gexicide


2 Answers

The difference between "" and <> isn't much. Both search for the header in implementation-defined places1, 2. The difference is that if that search fails for "", the search happens as if it was using <>. (§16.2)

Basically, this means that if <> finds a header with a certain name, "" does not fail to find a header with the same name3.


1 These implementation-defined places do not have to be the same for both forms.

2 There is no requirement that one of these search library folders and the other search the folder of the TU. The compiler is allowed to search the whole filesystem and even google for it if it wants.

3 This does not mean that they always find the same header, though.

like image 63
R. Martinho Fernandes Avatar answered Sep 21 '22 06:09

R. Martinho Fernandes


This is because of how the include syntax is defined.

#include <cstdio> means that the compiler should include the standard library cstdio

#include "cstdio" means the compiler should try to find the file "cstdio", looking primarily in the current directory and using the location of the standard libraries as a fallback.

like image 38
Agentlien Avatar answered Sep 20 '22 06:09

Agentlien