C++ Logo

std-proposals

Advanced search

Re: [std-proposals] constexpr support for std::chrono::system_clock

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Fri, 7 Mar 2025 13:29:52 +0100
It is not so simple: Sometimes you want identical uuids from the header file with those contents, sometimes you do not.   What is the identifing criterion here? The contents of the header file.   So to clearly identify and reproduce a specific uuid, you have to specify a unique name, e.g. in a comment before:   // header file for generating unique ids // used in more than one project in similar form // long long int uuid = UUID(); // unsafe // // unique comment: project_object_version long long int uuid2 = UUID(); // safe     If you need an unique comment, then you can directly use it as parameter to a constexpr function to generate an UUID.   (In your version it is also very difficult to get the same UUID, if the header file changes elsewhere   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Fr 07.03.2025 13:15 Betreff:Re: [std-proposals] constexpr support for std::chrono::system_clock An:std-proposals_at_[hidden]; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; An idea just came into my head now for generating UUID's in source code in such a way that the next build will be identical. So let's say there's a preprocessor macro called UUID that inserts a random 128-Bit number. The random UUID could be generated as follows:    1) Take the entire contents of the current source file (or just the current header file if the macro is in a header file)    2) Take contents from Step 1 and feed them into the MD5 hash function    3) For each use of the UUID macro, append the line and character number before computing the hash So let's say we have a header file called "myheader.hpp" which contains just one line as follows:    inline int monkey = UUID & 1; And let's say we have a source file "mysource.cpp" which contains two lines as follows:    #include "myheader.hpp"    int main(void) {} And so when the source file is put through the compiler, and the UUID macro is encountered, the entire contents of "myheader.hpp" gets inputted into a hash function. Next the line number and character number go into the hash function (i.e. "1 20"), and then the MD5 digest is computed, yielding a 128-Bit number. So unless you change the contents of some files, every header file will always generate the same UUID. So you've got identical builds. A few little nitty gritty points:    * The character '\r' should be ignored so that Linux and MS-Windows builds generate the same UUID    * (I'll think of more points later) -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-03-07 12:34:47