liveBook · Manning

Unicode escape

As explained in Modern C

A Unicode escape sequence is a C escape notation using \u or \U followed by hexadecimal digits to specify a Unicode code point.

Box-drawing characters

`#define VBAR "\u2502"` names a vertical bar for use in a C string. The four hexadecimal digits identify the character; they are not four characters to print. section 14.3

TAKEAWAY: A Unicode escape specifies a Unicode code point in C source using `\u` or `\U` followed by hexadecimal digits. It lets a string literal name a character without placing that character directly in the source. Specifying it is distinct from displaying it: the multibyte printing example switches locale before printing. section 14.3

43   #define VBAR "\u2502"      /**< a vertical bar character   */
44   #define HBAR "\u2500"      /**< a horizontal bar character */
45   #define TOPLEFT "\u250c"   /**< topleft corner character   */
46   #define TOPRIGHT "\u2510"  /**< topright corner character  */


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":2}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":12}],[{\"line\":1,\"ch\":5},{\"line\":1,\"ch\":12}],[{\"line\":2,\"ch\":5},{\"line\":2,\"ch\":12}],[{\"line\":3,\"ch\":5},{\"line\":3,\"ch\":12}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":2}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":12}],[{\"line\":1,\"ch\":5},{\"line\":1,\"ch\":12}],[{\"line\":2,\"ch\":5},{\"line\":2,\"ch\":12}],[{\"line\":3,\"ch\":5},{\"line\":3,\"ch\":12}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":2}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":12}],[{\"line\":1,\"ch\":5},{\"line\":1,\"ch\":12}],[{\"line\":2,\"ch\":5},{\"line\":2,\"ch\":12}],[{\"line\":3,\"ch\":5},{\"line\":3,\"ch\":12}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":2}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":12}],[{\"line\":1,\"ch\":5},{\"line\":1,\"ch\":12}],[{\"line\":2,\"ch\":5},{\"line\":2,\"ch\":12}],[{\"line\":3,\"ch\":5},{\"line\":3,\"ch\":12}]]"}
!@%STYLE%@!

Compare the escapes used for vertical, horizontal, and corner characters in string-literal macros. section 14.3

How Modern C covers it

How deep it goes
Defines the notation through concrete escapes but does not detail their encoding in printed multibyte strings.
Examples
Shows escapes for vertical and horizontal bars and two corner characters.
What it assumes
Assumes familiarity with C string literals and macros; introduces Unicode escapes in that setting.
What you can do after
Evaluate/understand how an escape names a character without itself ensuring that multibyte printing works.
How it connects
Connects Unicode code points with C string literals, preprocessor macros, locale, and multibyte printing.

Also explained in

Compare how 2 books explain Unicode escape →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.