C++ Logo

std-proposals

Advanced search

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

From: Fabio Alemagna <falemagn_at_[hidden]>
Date: Fri, 24 Nov 2023 13:47:38 +0100
If it's a compile-time random number that is desired, there are
library solutions out there that just do the job.

For example: https://stackoverflow.com/a/66169388/566849

Il giorno ven 24 nov 2023 alle ore 13:30 Frederick Virchanza Gotham
via Std-Proposals <std-proposals_at_[hidden]> ha scritto:
>
> On Thu, Nov 23, 2023 at 5:13 PM Thiago Macieira wrote:
> >
> > You can produce reproducible and non-random outputs with __COUNTER__. There
> > are pitfalls across TUs, but each TU is reproducible on its own.
>
>
> I say UUID as slang for a random 128-Bit number, as I think a lot of
> people do nowadays. Nobody cares about the different versions of UUID
> anymore. When we want a universally unique ID, we just want a random
> 128-Bit number. Nobody wants your MAC address tagged on to the date
> and time.
>
> But here's another idea:
>
> Let's say that __UUID__ is a 128-Bit number as follows:
> * The 96 most significant bits are the same as the 96
> least significant bits of the hash sum of the
> current source file (after all instances of '\r\n' have
> been replaced with '\n') combined with the hash of all
> the preprocessor macroes defined at the command line
> (for example "-DNDEBUG -D__WXMAC__ -D_FILE_OFFSET_BITS=64").
> * The remaining 32 least significant bits are __COUNTER__
>
> This would mean we have reproducible builds.
>
> Not sure what we would do about having identical source code files
> (i.e. with the same hash sum) or even if that would make any sense --
> I mean in order to avoid the one-definition rule, all functions would
> have to be static-linkage or inside an anonymous namespace, meaning
> they would be totally inaccessible outside the translation unit,
> unless of course there were _one_ external linkage function providing
> access to them -- but then that would violate the ODR.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-11-24 12:47:51