#include search paths

Guy Harris guy at auspex.UUCP
Sat Nov 12 03:40:10 AEST 1988


>When I have a line like '#include <fred.h>' I was under the impression
>that /usr/include was searched for fred.h first due to the use of <> instead
>of quotes.  Is this true?

Yes.

>And where did I get this idea??

Probably from any of a number of documents about C implementations on
UNIX.

>Now that I need to verify it I can't find squat that tells me the
>difference between <> and quotes.

>From the SunOS 4.0 man page CPP(1) - other UNIX implementations may have
similar stuff in their documentation (this came from some version of the
S5 CPP(1) man page):

     #include "filename"
     #include <filename>
          Read in the contents  of  filename  at  this  location.
          This data is processed by cpp as if it were part of the
          current file.  When the <filename>  notation  is  used,
          filename  is  only searched for in the standard include
          directories.  See the -I and -Y options above for  more
          detail.   No  additional  tokens  are  permitted on the
          directive line after the final " or >.

  Details
  Directory Search Order
     #include files is:

     1.  The directory of the file  that  contains  the  #include
         request (that is, #include is relative to the file being
         scanned when the request is made).

     2.  The directories specified by  -I  options,  in  left-to-
         right order.

     3.  The standard directory(s)  (/usr/include  on  UNIX  sys-
         tems).

(the above description applies to most, if not all, UNIX systems, except
for the "-Y" option which may not be present on all UNIX systems).

And from K&R second edition:

   A 12.4 File Inclusion

	A control line fo the form

		# include <filename>

   causes the replacement of that line by the entire contents of
   the file "filename". ...  The named file is searched for in a
   sequence of implementation-dependent places.

	Similarly, a control line of the form

		# include "filename"

   searches first in association with the original source file (a
   deliberately implementation-depenent phrase), then as if in the first
   form. ...



More information about the Comp.lang.c mailing list