C++ Logo

sg15

Advanced search

Re: Questions about wording and design intention for header units and ideas

From: 许传奇(夜灯) <"许传奇>
Date: Mon, 22 May 2023 09:48:58 +0800
Hi Boris,
> The standard is pretty clear that an imported header does not "see"
any macros defined by the importer.
This is surprising to me. Where is the corresponding wording? I just searched
the context and didn't find the wording. And if it is true, it implies that the following
transition is invalid, isn't it?
```
// foo.h
#define FOO_H
// bar.h
#ifdef FOO_H
...
#else
...
#endif
// user.orig.cpp
#include "foo.h"
#include "bar.h"
// user.cpp
import "foo.h";
import "bar.h";
```
Now we can't assume `user.cpp` isn't the same with `user.orig.cpp`. It is surprising since such patterns are
pretty common in practice. And I'm worrying that we'll meet problems if this is true.
> I think these concerns should be addressed by SG15. An implementation dependent configuration file like you suggest is one way forward. Another would be for SG15 to specify a #pragma directive or magic comment (similar to the "-*- coding: <encoding name> -*-" comment that some editors recognize as an indication of source code character encoding; e.g. a "// importable-header" comment; I'm not suggesting this is a good idea).
I remember Iain had a similar idea. But this was rejected due to the intention of header units is to adopt module-like things easily without a touch to the existing code. But such ideas break such assumption. So maybe we can't decide if a header is importable header by changing its source code.
Thanks,
Chuanqi
------------------------------------------------------------------
From:Boris Kolpackov <boris_at_[hidden]>
Send Time:2023 May 21 (Sun.) 16:56
To:Tom Honermann via SG15 <sg15_at_[hidden]>
Cc:Chuanqi <chuanqi.xcq_at_[hidden]ba-inc.com>; Tom Honermann <tom_at_[hidden]>
Subject:Re: [SG15] Questions about wording and design intention for header units and ideas
Just one to point out that the assumption in the motivating example
(that started this discussion) is incorrect:
> On 5/17/23 2:16 AM, "许传奇(夜灯)" <chuanqi.xcq_at_[hidden]> wrote:
>
> > First, the motivation example:
> >
> > ```
> > // a.cpp
> > import "foo.h";
> >
> > // b.cpp
> > #define M 43
> > import "foo.h"
> > ```
> >
> > The question is, for build systems, how can they know if they should
> > use the same BMI for these 2 imports. Since **currently** the build
> > systems don't have a **good** method to know whether a macro is
> > interesting to a specific file.
The standard is pretty clear that an imported header does not "see"
any macros defined by the importer.

Received on 2023-05-22 01:49:04