From: Kaz Kylheku
Newsgroups: comp.lang.c
Subject: Re: include "file" or include <file>?
Message-ID: <>
Date: Thu, 06 May 1999 05:16:54 GMT

On 6 May 1999 01:19:13 GMT, RaMzEyMe wrote:
>What's the difference between putting
>      include "file"      or      include <file>
>in the preprocessor?

Let me draw you a diagram.

        |                                               |
        |         +--------------------------+          |
        |         | places searched          |          |
        |         | for <> includes          |          |
        |         +--------------------------+          |
        | places searched for "" includes               |

Mnemonic: the <> suggests enclosure.

According to the language standard, a C implementation searches for headers in two different ``places'' if they are included with "". It first looks in one place, and if it doesn't find the header there, it looks in the other place.

Headers that are included with <> are only searched for in the second place.

Imagine that the above diagram is being visited from outside in.

How this is done in actual implementations is quite commonly like this: headers included with "" are first looked for in the same place where their parent file (the one containing the #include) is located. If they are not found there, certain pre-defined places are searched; usually directories containing headers that came with the implementation.

Various compilers have various ways to influence the behavior, which leads some programmers to structure their projects in various clever ways, such as separating the include files from the source files. Sometimes people even influence the compilers to use <> searching for their own

The most portable thing to do is to use "" for including files within your project, to use <> only for implementation supplied files. Furthermore, at least for small to moderately sized projects, the easiest thing to do is to have all of the files collected in one place (i.e directory). This poses the fewest build management and portability headaches.