C++ Logo

std-proposals

Advanced search

Re: [std-proposals] __COUNTER__

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Fri, 23 Aug 2024 11:33:31 +0300
On 8/23/24 04:11, Jeremy Rifkin via Std-Proposals wrote:
>
> It's unclear to me that __FILE__ is enough to help with ODR issues and
> providing truly unique identifiers. Canonical
> paths break down for hardlinks.

Why? Hardlinks or not, files located at different canonical paths should
be considered as distinct files, even if their content is the same.

> Some #pragma once implementations use
> file contents to uniquely identify files, that
> could be used here, however this is becoming increasingly complex.

To my knowledge, `#pragma once` do not and must not use file contents
for determining of the file was included. Otherwise, it would break
semantics for distinct files with the same content. It must be based on
file uniqueness, i.e. either inode or canonical path comparisons.

> I'm weary of feature-creeping this paper; my goal is to standardize
> existing practices rather than introduce new
> features. It might be worth considering this for a follow-on paper.
> Even if some sort of __UUID__ were provided, it
> would still be beneficial to standardize __COUNTER__ given its widespread use.

Existing practice may not be the thing to standardize if there is a
significant drawback to it. ODR issues related to __COUNTER__ are such a
drawback, and I don't think you can solve it without dropping the
concept of a counter altogether.

Received on 2024-08-23 08:33:35