liveBook · Manning

UTF-8

As explained in Modern C

UTF-8 is a Unicode Transformation Format that encodes code points as sequences of 8-bit code units.

A source file, a text file, and a terminal may not use the same multibyte encoding. Text that works in one environment can therefore cause trouble when moved to another. UTF-8 is one of Unicode’s three widely used transformation formats; the others are UTF-16 and UTF-32. section 14.3

Requesting UTF-8 in C

Since C11, u8"text" is a UTF-8 string literal with type char[]. Compare u"text" and U"text", whose types are char16_t[] and char32_t[]. The u8 prefix is useful when an encoding must be ensured, for example in network communication. section 14.3

TAKEAWAY: A modern platform’s ordinary multibyte encoding may already be UTF-8, but do not assume every environment uses it. The u8 prefix states the intended encoding without relying on the locale. section 14.3

How Modern C covers it

How deep it goes
Defines UTF-8 among Unicode formats and shows C11 literal syntax, but does not detail its byte encoding.
Examples
Contrasts u8"text", u"text", and U"text", with network communication as a reason to ensure an encoding.
What it assumes
Assumes familiarity with C string literals and the idea of multibyte text; introduces the Unicode encoding names in context.
What you can do after
Operate/configure it by choosing a C11 u8 literal when UTF-8 must be ensured.
How it connects
Links UTF-8 to Unicode, multibyte strings, locales, UTF-16, UTF-32, and C string literals.

Also explained in

Compare how 11 books explain UTF-8 →

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.