[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
C compiler include file searching (was: per-target vpath alternatives)
From: |
Philip Guenther |
Subject: |
C compiler include file searching (was: per-target vpath alternatives) |
Date: |
Mon, 10 Sep 2007 14:05:12 -0600 |
[The topic has shifted, so I've changed the subject]
On 9/10/07, Eli Zaretskii <address@hidden> wrote:
> > Date: Sun, 9 Sep 2007 21:40:38 -0600
> > From: "Philip Guenther" <address@hidden>
> > Cc: address@hidden
> >
> > In my experience, C
> > compilers in UNIX search the directory of the source file, whether or
> > not that directory is named in a -I option.
>
> Only if you say `#include "foo.h"', not `#include <foo.h>'.
Agreed.
> The C standard specifies that "foo.h" is looked for in the current directory
> first.
I don't believe the C standard states that, especially given that
there's no formal concept of "directory", much less "current
directory" in the C standard. The draft of the C99 I'm looking at
says, in section 6.10.2p3:
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.
The Single Unix Specification *does* specify the behavior I described.
To quote http://www.opengroup.org/onlinepubs/000095399/utilities/c99.html
-I directory
Change the algorithm for searching for headers whose names are
not absolute pathnames to look in the directory named by the
directory pathname before looking in the usual places. Thus,
headers whose names are enclosed in double-quotes ("") shall
be searched for first in the directory of the file with the
#include line, then in directories named in -I options, and
last in the usual places. For headers whose names are enclosed
in angle brackets ("<>"), the header shall be searched for
only in directories named in -I options and then in the usual
places. Directories named in -I options shall be searched in
the order specified. Implementations shall support at least
ten instances of this option in a single c99 command invocation.
Note that the first place looked is *NOT* the current directory but
rather the directory containing the source file. That distinction is
important to many makefiles that build source from multiple
directories and should not be overlooked.
Philip Guenther
- C compiler include file searching (was: per-target vpath alternatives),
Philip Guenther <=