🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Header file inclusion and multiple directories

#2400
From: Matt Austern
Date: Thu, 02 Nov 1995 23:44
59 lines
2793 bytes
Consider a project that spans several directories.  In particular,
let's suppose it has the files project/d1/base.h,
project/d1/derived.h, and project/d2/main.cc.  Here are some code
fragments.

// project/d1/base.h
class B {/* ... */};


// project/d1/derived.h
#include "base.h"

class D : public B { /* ... */ };


// project/d2/main.cc
#include "../d1/derived.h"

int main() { /* ... */ }


The question: what happens when you compile main.cc?  I've tried it
with a few of the popular compilers; the answer is that some compilers
will include derived.h and then in turn include base.h, while some
compilers will include derived.h, search for base.h in d2, then fail
because they can't find d2/base.h.

Each of these behaviors is, of course, standard conforming: section
16.2 of the draft standard simply says that "The named source file is
searched for in an implementation-defined manner."

This is frustrating for two reasons.  The first is simply one of
portability: multi-directory programs are common, and this lack of
specification makes it hard to do this portably.  Second, it seems
clear to me that, in this case, a compiler that searches for base.h in
d1 is more useful than one that searches in d2.  It's a pity that both
are equally valid according to the standard.

Now I can certainly understand why the standard leaves this as
implementation defined: not all platforms have hierarchical file
systems (or even file systems at all in a conventional sense), so it
would be difficult to say anything useful that didn't make
impermissible assumptions about the platform.  It's still frustrating,
though.

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?
-- 
  Matt Austern                             He showed his lower teeth.  "We 
  matt@physics.berkeley.edu                all have flaws," he said, "and 
  http://dogbert.lbl.gov/~matt             mine is being wicked."

---
[ 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: <MATT.95Nov2152444@cyclops5.berkeley.edu>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: matt@cyclops5.berkeley.edu (Matt Austern)
Newsgroups: comp.std.c++
Subject: Header file inclusion and multiple directories
Date: 02 Nov 1995 23:44:55 GMT
Organization: University of California at Berkeley (computational neuroscience)
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Nov2152444@cyclops5.berkeley.edu>
Reply-To: matt@physics.berkeley.edu
NNTP-Posting-Host: physics2.berkeley.edu