C++ Logo

sg15

Advanced search

Re: [SG15] Determining identity like #pragma once

From: Richard Smith <richardsmith_at_[hidden]>
Date: Tue, 9 Jul 2019 17:07:19 -0700
On Tue, Jul 9, 2019 at 6:23 AM Ben Craig via SG15 <sg15_at_[hidden]>
wrote:

> tl;dr: Should the Tooling TR provide guidance on how to determine header
> unit identity?
>
>
>
> The compiler is only supposed to import / include a header unit once, no
> matter how many times it sees the directive. This is similar to the
> popular vendor extension “#pragma once”. Like “#pragma once”, the compiler
> needs to be able to tell when a header unit is the same. This is tricky.
> In a single TU, #include “foo.h” could refer to two different header
> units. #include “bar.h”, import <bar.h>, and #include <dir/bar.h> could
> all refer to the same header unit.
>
>
>
> The different compilers use different approached for determining
> identity. Some use the file path (this breaks with hard links). Some use
> the file identity / inode (network shares can break this). I believe some
> even use the file contents (seems slow?). Should the Tooling TR recommend
> an approach for identity comparison, or are we happy leaving this up to the
> implementers?
>

I think it would make sense for the TR to include a recommendation (or
rather, one per platform).

Received on 2019-07-09 19:09:27