I’ve got the following code that someone working on MSVC has given to me:
#define MAP1(x, y) map[#x] = #@y;
I’m on Xcode, using Clang, and from various google searches I’ve found that this is known as a ‘charizing operator’, and is specific to MSVC’s preprocessor. Is there a way of emulating the functionality of this operator while using Clang? I’ve tried removing the @ but got the following error message:
Assigning to 'int' from incompatible type 'const char[2]'
Would an explicit cast to ‘int’ work or is the charizing operator doing something different?
The stringizing operator (standard C++) converts
ainto"a", so the charizing operator sounds like it turnsainto'a'. You can, in the simple cases, get'a'from"a"by taking the first character.The
static_casttoconst char(&)[2]ensures you get a compile-time error if you don’t get a string of length 1, which is two characters if you count the trailing'\0'. A plain#y[0]would silently take the first character, regardless of the string’s length.