Hi,
I'm wondering if this is intended behaviour in the Microsoft C/C++ compiler (target arch x86 or x64 - same behaviour, version 19.29.30040). I'm trying to make a multi-character constant as follows:
#include <stdio.h>
int main() {
printf("0x%08x\n", 'ABCC');
}
and the result is, expectedly, 0x41424343. The characters are encoded in a little endian order, so the 'C's constitute the two lowest-order bytes of the 32-bit integer.
Now I want to replace the characters 'C' with a backslash:
#include <stdio.h>
int main() {
printf("0x%08x\n", 'AB\\\\');
}
and the result is... 0x5c41425c. Why is that? The backslashes now occupy one lowest-order byte and one highest-order byte, which is what I would expect from the character constant '\\AB\\', but definitely not 'AB\\\\'. For comparison, gcc, clang and icc all compile the second snippet to print 0x41425c5c.
Is this intended or a bug in the compiler? I'm aware that generally multi-character constants are a portability nightmare, and according to the C++ standard they are implementation-defined. However I haven't found any information about special handling of the backslash on any Microsoft page.
If this is intended, I would suggest adding this information here https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp to the "Microsoft-specific" section, since IMO this behaviour is undoubtedly unexpected.