What is the difference between the U prefix for a character literal versus a string literal?

In the C ++ C ++ programming language 4th edition, section 6.2.6, it says:

Combinations of the prefixes R, L, and u are allowed, for example, uR "** (foo \ (bar)) **". Note the sharp difference in the value of the U prefix for a character (unsigned) and for the encoding of a UTF-32 string (§7.3.2.2).

I do not quite understand what the author is trying to say here. What is the "dramatic difference"? Why is the word "(unsigned") used here?

In my understanding, the U-prefixed character literal contains the ISO-10646 code point value of the quoted character, which basically represents the same idea as the U prefix of a string literal, and has nothing to do with the unsigned concept.

+4
source share
1 answer

unsigned is a C ++ keyword and means that the integer type that (in most cases) follows in the declaration has only positive values.

For reference, see here: http://en.cppreference.com/w/cpp/language/types

Now for char and char [] you have:

char16_t c = u'\u00F6';
char32_t d = U'\U0010FFFF';
char16_t C[] = u"Hell\u00F6";
char32_t D[] = U"Hell\U000000F6\U0010FFFF";

For additional reference to string literals: Unicode encoding for string literals in C ++ 11

Indeed, there is some difference between uand uand unsigned, but I do not consider it dramatic.

0
source

Source: https://habr.com/ru/post/1524453/


All Articles