What are the differences among L'\x1234', '\u1234', u'\x1234' and L'\u1234' in C (C11 and newer versions)?
Apparently a character constant with prefix L is of type wchar_t and a constant with prefix u is of type char16_t. An escape sequence starting with \x means the character with the given code in the Execution Character Set (ECS) of the compiler and an escape sequence starting with \u means the character with the given code in UTF-16.
What is the type of '\u1234' (without the prefix L)? What is the integer value of L'\u1234'? The code of the character with UTF-16 code 0x1234 in the ECS? Does the character denoted by u'\x1234' has a UTF-16 code of 0x1234 or it depends on the ECS?
The type of
'\u1234'isint. IfCHAR_MAXis greater than or equal to 0x1234 (4660) then the value of'\u1234'is 0x1234 (4660). Otherwise, the value of'\u1234'is implementation-defined.The type of
L'\u1234'iswchar_t. If the value 0x1234 (4660) exists as a member of the extended character set and it represents the character designated by the universal character name\u1234in the source character set then the value ofL'\u1234'is 0x1234 (4660). Otherwise the value ofL'\u1234'is implementation-defined.0x1234 is not a character constant. Whether there is a single member of the extended execution character set, a sequence of more than one member of the extended execution character set, or no sequence of members of the extended execution character set that represents a character corresponding to UTF-16 code 0x1234 is implementation-defined.
The type of
u'\x1234'ischar16_t. The value ofu'\x1234'is 0x1234 (4660). A program may interpret the value 0x1234 (4660) as a UTF-16 code unit value.