Appending a string literal with a compile time generated integer
<p>I'm trying to generate a string during compile-time that contains a constant string and a couple calculated integers.</p>

<p>This string is to be used in GCC's <code>__attribute__((section("")))</code> directive.</p>

<p>The purpose of the whole thing is to put a few variables in an ELF file, each with a unique section name.</p>

<p>I used to do this by compiling each object file with <code>-DSOME_SYMBOL=&lt;file_source_CRC&gt;</code> to differentiate between object files, and <code>__COUNTER__</code> to differentiate between variables inside of a single object file. (We use this because of a requirement from our logging solution)</p>

<p>So the resulting code would be used using something like this:</p>

<pre><code>#define SOME_MACRO(msg) {\
    static const char *messageBuffer __section__((section(".msg" ## #SOME_SYMBOL ## #__COUNTER__))) = {msg};\
} // Approximation

SOME_MACRO("This is a string");
</code></pre>

<p>This solution works great, but it requires support from the build-system (calculating the CRC and injecting it as a GCC <code>-D</code> flag), and it became a bit of an overhead when we moved from Makefile to SCons.</p>

<p>So I searched for another solution, and found this <a href="http://www.codeproject.com/Tips/627020/constexpr-CRC-using-user-defined-literal" rel="nofollow noreferrer">compile time CRC solution</a>, but I got a bit lost when trying to figure out how to append it to the string.</p>

<p>After a bit more searching, I found the <a href="https://stackoverflow.com/questions/23999573/convert-a-number-to-a-string-literal-with-constexpr">following answer</a>, which explains how to convert an integer to a string using template metaprogramming, but I still couldn't figure out how to append the strings (again, during compile time).</p>

<p>I'd love to find a solution for this problem.</p>