开发者

Can anyone tell me what does this mean

开发者 https://www.devze.com 2023-03-14 14:31 出处:网络
This is a very basic doubt, but clarify me please #define TLVTAG_APPLICATIONM开发者_开发技巧ESSAGE_V\"\\xDF01\"

This is a very basic doubt, but clarify me please

#define TLVTAG_APPLICATIONM开发者_开发技巧ESSAGE_V             "\xDF01"
printf("%s\n", TLVTAG_APPLICATIONMESSAGE_V);

means what will be printed.


To go step by step (using the C++ standard, 2.13.2 and 2.13.4 as references):

The #define means that you substitute the second thing wherever the first appears, so the printf is processed as printf("%s\n", "\xDF01");.

The "\xDF01" is a string of one character (plus the zero-byte terminator), and the \x means to take the next characters as a hex value, so it attempts to treat DF01 as a number in hex, and fit it into a char.

Since a standard quoted string contains chars, not wchar_ts, and you're almost certainly working with an 8-bit char, the result is implementation-defined, and without the documentation for your implementation it's really impossible to speculate further.

Now, if the string were L"\xDF01", its elements would be wchar_ts, which are wide characters, normally 16 or 32 bits, and the DF01 value would turn into one character (presumably Unicode) value, and the print statement would print characters \xDF and characters \x01, not necessarily in that order, since printf prints char, not wchar_t. wprintf would print out the whole wchar_t.


It seems somebody is trying to print an unicode character -> �

0

精彩评论

暂无评论...
验证码 换一张
取 消