C++ Logo

sg15

Advanced search

[SG15] Determining identity like #pragma once

From: Ben Craig <ben.craig_at_[hidden]>
Date: Tue, 9 Jul 2019 13:23:31 +0000
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?


Received on 2019-07-09 08:25:27