🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2418

Re: Header file inclusion and multiple directories

#2418
From: Ajay Kamdar
Date: Fri, 03 Nov 1995 20:55
52 lines
2629 bytes
In article <MATT.95Nov2152444@cyclops5.berkeley.edu>,
Matt Austern <matt@physics.berkeley.edu> wrote:

>So my challenge: can anyone think of an acceptable replacement for
>"The named source file is searched for in an implementation-defined
>manner" that would provide a bit more of a guarantee of reasonable
>behavior?


A change in the WP in not necessary to get a guaranteed reasonable 
behavior across multiple platforms and multiple compilers.

a) Use the < and > delimiters to include _all_ the header files.
   16.2.1 guarantees an implementation defined sequence of places
   is searched to find the desired header file.

b) Use the implemenation defined syntax to specify the search order
   so that all the directories from which header files are to be
   included are listed in the search list.
   
   All C++ compilers that I know of on all systems I have used
   invariably provide either a -I compiler option or some equivalent
   switch to set up the search order for header files.
   
c) Always specify the current directory (-I. if your compiler supports
   the -I option) as the *first* directory to search for header files.
   This results in a behavior similar to using the "" delimiters minus
   the unpredictability associated with that other syntax.
   
Hence making the following change to your example:

// project/d2/main.cc
#include <derived.h>     // Now using < and > delimiters

and compiling as follows (assuming -I is the implementation dependent
                          method of setting up the header search order
                          and that the compiler goes in the order in
                          which the -I options are specified)
                          
   CC -I. -I../d1 main.c
   
will always work with any C++ compiler and find the base.h header file.

-- 
Ajay Kamdar        |    Email: ajay@lehman.com    |    Standard Disclaimer 
Lehman Brothers    |    Phone: (201) 524-5048     |

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <47dtbl$69p@jabba.lehman.com>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <MATT.95Nov2152444@cyclops5.berkeley.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: ajay@lehman.com (Ajay Kamdar)
Newsgroups: comp.std.c++
Subject: Re: Header file inclusion and multiple directories
Date: 03 Nov 1995 20:55:49 GMT
Organization: Lehman Brothers, Inc.
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <47dtbl$69p@jabba.lehman.com>
References: <MATT.95Nov2152444@cyclops5.berkeley.edu>
NNTP-Posting-Host: physics2.berkeley.edu