Given the code
// somewhere in the program
const char* p1 = \"Hello World\";
// somewhere else in the program
const char* p2 = \"Hello World\";
Identical literal strings are not guaranty to be identical, but as you use MACRO to create the string, you can change it to return identical string.
gcc/clang have an extension to allow to build UDL from literal string:
template
struct CsHelper
{
static constexpr const Char s[] = {Cs..., 0}; // The unique address
};
// That template uses the extension
template
constexpr auto operator"" _cs() -> const Char (&)[1 + sizeof...(Cs)] {
return CsHelper::s;
}
and then
#define nameof(id) #id ## _cs
See my answer from String-interning at compiletime for profiling to have MAKE_STRING macro if you cannot used the extension (Really more verbose, and hard coded limit for accepted string length).