<div dir="auto">There was a proposal for compile-time mutable variables in 2019:<div dir="auto"><a href="https://github.com/cplusplus/papers/issues/602">https://github.com/cplusplus/papers/issues/602</a></div><div dir="auto"><br></div><div dir="auto">Which would be more useful I think. Don&#39;t think macros are the right way to go for something like this.</div><div dir="auto"><br></div><div dir="auto">- Jonas</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Frederick Virchanza Gotham via Std-Proposals &lt;<a href="mailto:std-proposals@lists.isocpp.org" target="_blank" rel="noreferrer">std-proposals@lists.isocpp.org</a>&gt; schrieb am Mi., 22. Nov. 2023, 13:06:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Lots of people make use of the __COUNTER__ macro in their code for<br>
generating unique identifiers and unique types, and for a unique<br>
incrementing number.<br>
<br>
Last week I wrote code that combined __COUNTER__ with __FILE__ to get<br>
a string which hopefully would be unique for the entire program.<br>
<br>
So then I was thinking, what if the preprocessor could help us here<br>
and give us a 128-Bit random number? What if there were to be five new<br>
macros that would expand as follows:<br>
<br>
#define __UUID__ 0f234c3ac9ec4d7bab8e2fcac3da8a5c<br>
<br>
#define __UUIDstr__ &quot;0f234c3ac9ec4d7bab8e2fcac3da8a5c&quot;<br>
<br>
#define __UUIDstrH__ &quot;0f234c3a-c9ec-4d7b-ab8e-2fcac3da8a5c&quot;<br>
<br>
#define __UUIDint128__ 0x0f234c3ac9ec4d7bab8e2fcac3da8a5c<br>
<br>
#define __UUIDint64__ 0x0f234c3ac9ec4d7b, 0xab8e2fcac3da8a5c<br>
<br>
Of course __UUIDint128__ can only be used on compilers that have an<br>
unsigned integer type at least 128 bits wide and which allow 128-Bit<br>
literals. Here&#39;s some sample usages:<br>
<br>
    #include &lt;cstdint&gt;<br>
    #include &lt;iostream&gt;<br>
    using std::cout, std::endl;<br>
<br>
    #define CONCATx(a,b) a##b<br>
    #define CONCAT(a,b) CONCATx(a,b)<br>
<br>
    int main(void)<br>
    {<br>
        unsigned CONCAT(some_variable_,__UUID__) = 68u;<br>
<br>
        some_variable_0f234c3ac9ec4d7bab8e2fcac3da8a5c = 67u;<br>
<br>
        cout &lt;&lt; &quot;Your build key to give to production is {&quot; &lt;&lt;<br>
__UUIDstrH__ &lt;&lt; &quot;}\n&quot;;<br>
<br>
        std::uint64_t my_uuid[2u] = { __UUIDint64__ };<br>
<br>
        __uint128_t myuuid = __UUIDint128__;<br>
    }<br>
<br>
Furthermore, to do away with the need for the CONCAT macro, I suggest<br>
that the following line:<br>
<br>
        unsigned CONCAT(some_variable_,__UUID__) = 68u;<br>
<br>
can be simplified to:<br>
<br>
        unsigned some_variable_###__UUID__### = 68u;<br>
<br>
So the three hash symbols (or pound symbols in the US) are used by the<br>
preprocessor to concatenate two sequences of characters together<br>
without a space between them. So you could also use this tripple-hash<br>
in your own code, such as:<br>
<br>
    #define monkey donkey<br>
    unsigned myvar_###monkey### = 7;<br>
    myvar_donkey = 8;<br>
-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div>

