C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Get UUID at compile-time from compiler (sort of like __COUNTER__)

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Thu, 23 Nov 2023 17:56:47 +0300
On 11/23/23 17:31, Frederick Virchanza Gotham via Std-Proposals wrote:
> On Thu, Nov 23, 2023 at 1:56 PM Lénárd Szolnoki via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> I have two concerns:
>>
>> 1. A similar concern with COUNTER, if it appears in header files it's can be a source of ODR violation.
>> 2. Reproducible builds
>
>
> No. 1 isn't a concern because the __UUID__ will always be different --
> you're just asking the compiler for a random 128-Bit number.

UUID is not a random 128-bit number. UUID has a structure, and not all
bits contribute to its uniqueness. See:

https://datatracker.ietf.org/doc/html/rfc4122#section-4.1

> As for No. 2, well instead of it being a random 128-Bit number, maybe
> it could be a 128-Bit number consisting of:
> (1) 64 bits to somehow identify the file (perhaps a hash of the filename?)

The same file can be reached through different paths, so the hash of the
path does not uniquely identify a file.

> (2) 32 bits to identify the line number
> (3) 32 bits that increment like how __COUNTER__ does
>
> This would allow us to hit 'Build' a second time and get the same
> executable file.

Received on 2023-11-23 14:56:51