Take the 2-minute tour ×

The C++ standard (I noticed it in the new one, but it did already exist in C++03) specifies universal character names, written as \uNNNN and \UNNNNNNNN and representing the characters with unicode codepoints NNNN/NNNNNNNN. This is useful with string literals, especially since explicitly UTF-8, UTF-16 and UCS-4 string literals are also defined. However, the universal character literals are also allowed in identifiers. What is the motivation behind that?

The syntax is obviously totally unreadable, the identifiers may be mangled for the linker and it's not like there was any standard function to retrieve symbols by name anyway. So why would anybody actually use an identifier with universal character literals in it?

Edit: Since it actually existed in C++03 already, additional question would be whether you actually saw a code that used it?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

It allows a system allowing unicode characters in identifier to export the source in a format compilable on any standard conforming compilers. I.E. it is a way to encode unicode over the basic character set (more or less like quoted-printable is used for email, systems who knows better are able to do a better job, other systems are still working).

share|improve this answer
add comment

C++ requires that actual extended characters appearing literally in source behave identically with Universal Character Names. Allowing Universal Character Names in identifiers permits programmers to use extended characters in identifiers.

share|improve this answer
It actual extended characters are supported, they have to behave as corresponding universal characters. But they don't have to be supported. –  Jan Hudec Jan 17 '13 at 7:46
add comment

Someone may want to create an identifier using a foreign language character that is not enterable on the keyboard or input device. Alternatively, the identifier may contain a character that is not printable using the font or output capabilities of the device but the IDE wants to show an accurate representation.

share|improve this answer
In the first case, the identifier wouldn't look like having that character, so the code would be unreadable and the identifier does not really matter to the machine. And for the second, representation in IDE is a completely separate problem. –  Jan Hudec Sep 26 '12 at 8:02
add comment

Your Answer


