8

In The C++ Programming Language C++ 4th edition, section 6.2.6, it says:

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

I don't quite understand what the author is trying to say here. What is the "dramatic difference" indeed? Why is the word "(unsigned)" used here?

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

goodbyeera
  • 3,169
  • 2
  • 18
  • 39
  • I don't understand either. `U"hello"` is a `char32_t const[6]` and `U'h'` is a `char32_t`. There's no dramatic difference to me. – Simple Jan 30 '14 at 09:37
  • @Simple Maybe the book is wrong? Or it is a matter of how you look at it whether you consider the differnce as dramatic or not? – TobiMcNamobi Jan 30 '14 at 09:44
  • All I can think is that a `U` *suffix* on an integer literal makes it unsigned? `char i = -159U; std::cout << i;` // prints "a"` – Tristan Brindle Jan 30 '14 at 09:51

1 Answers1

0

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

For reference look 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 further reference to string literals: Unicode encoding for string literals in C++11

So indeed there is some difference between u and U and unsigned but I wouldn't consider it dramatic.

Community
  • 1
  • 1
TobiMcNamobi
  • 4,687
  • 3
  • 33
  • 52
  • I may have made myself unclear with the original phrasing of the question. I have modified the question. I know what "unsigned" is as a C++ keyword. Sorry for the confusion. – goodbyeera Jan 30 '14 at 09:35