When we write a program which supports both unicode and multibytes,
we often use _T(“some string”) macro for strings.
But, does a character also need to wrap this macro?
Are L’A’ and ‘A’ totally same?
Don’t we need to wrap _T(‘A’) for a character?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you write
'A', and that value gets converted towchar_t, then on Microsoft compilers at least, it will have the same value as if you’d writtenL'A'or_T('A').The same can’t be said of string literals, since there is no useful conversion from
const char*toconst wchar_t*. I think this means it’s rather less important to get character literal types right, than string literals.It’s easy to write code that behaves differently according to whether a character literal is wide or narrow – just have an overloaded function that does something completely different. But in practice, sensible functions overloaded to take both types of character are going to end up doing the same thing with
'A'that they do withL'A'. And functions which aren’t overloaded, and only takewchar_t, can take'A'just fine.I don’t immediately see anything in the standard to require that
L'A' == (wchar_t)'A', so in theory non-Microsoft compilers might do something completely different. But you’d normally expect the wide character set to be an extension of the narrow character set, just as Unicode extends ISO-8859-1. To be specific what “extension” means, code points which are equal as integers designate the “same character”.