C++ Logo


Advanced search

Re: "logical name" of importable headers

From: Daniel Ruoso <daniel_at_[hidden]>
Date: Fri, 3 Jun 2022 10:30:55 -0400
Em sex., 3 de jun. de 2022 às 07:26, Nathan Sidwell via SG15
<sg15_at_[hidden]> escreveu:
> Indeed. Even in header-file land I don't think there's general
> agreement about what constitutes 'the same header'. (And hence some
> horrible corner cases of '#pragma once'/ #import)

It seems we have a tension between:

 * wanting header unit import to look exactly like header lookup

 * having to specify all header units in the command line

 * having the header accessible only via its "intended" interface.

Given that tension, here's a few outcomes that I think are desirable:

 1. The header file used to translate a header unit should be the same
file that the include statement would have found (i.e.: include and
import are symmetric).

 2. We need to be able to specify header units where they are only
accessible via their intended interface.

 3. We need to be able to specify header units where the matching is
done on the header file, and the resolution is entirely based on the
`-I` and include-"" rules.

Now, there's one problem that comes up if we combine specifying the
intended interface of a header unit, and still expect the `-I`
resolution to drive resolving the specific file, which would be that
you may end up with header units being shadowed by the order of `-I`.
This, IMHO, is a very undesirable outcome. There's nothing more
frustrating than weird things that happen because the `-I` arguments
get sorted in different ways for arbitrary reasons.

So here's a proposal to address that problem, which I think actually
gives us a path away from the problems with overlay of `-I` arguments
in general:

When you specify to the compiler that you have a header unit
`<foo.h>,/usr/include/foo.h`, the token `<foo.h>` is assigned to
`/usr/include/foo.h` regardless of `-I` arguments, and that applies
both to `import <foo.h>` and to `#include <foo.h>`.

If, on the other hand, you specify that you have a header unit
`/usr/include.foo.h`, you are communicating that you want the compiler
to follow it's normal include resolution, and only if the same file
(normalized with `realpath`) is found, you should consider it a match
for the header unit.


Received on 2022-06-03 14:31:08