maheshgupta024
maheshgupta024

Reputation: 7877

Can anyone tell me what does this mean

This is a very basic doubt, but clarify me please

#define TLVTAG_APPLICATIONMESSAGE_V             "\xDF01"
printf("%s\n", TLVTAG_APPLICATIONMESSAGE_V);

means what will be printed.

Upvotes: 3

Views: 351

Answers (2)

David Thornley
David Thornley

Reputation: 57036

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.

Upvotes: 6

karlphillip
karlphillip

Reputation: 93410

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

Upvotes: 4

Related Questions