liveBook · Manning

Wide character

As explained in Modern C, Third Edition

A wide character is a value of type wchar_t that represents exactly one character from an extended character set.

A wide character is a value of type wchar_t representing exactly one character from an extended character set. It provides a character-oriented counterpart to multibyte strings, whose byte count does not directly reveal the number of printed characters. section 14.3

Converting multibyte text

The C interface converts multibyte text into wchar_t values with mbsrtowcs, while mbrtowc converts one multibyte character and accepts an mbstate_t parsing state. section 14.3

Use wide characters with these constraints:

  • Preserve mbstate_t when parsing sequences whose characters may occupy multiple bytes. section 14.3
  • Account for locale configuration when printing or interpreting multibyte characters. section 14.3
  • Check implementation assumptions about wchar_t, Unicode code points, and basic character-code agreement. section 14.3
 size_t mbsrtowcs(wchar_t*restrict dst, char const**restrict src,
                  size_t len, mbstate_t*restrict ps);

Inspect the standard conversion signature for transforming multibyte input into wide characters. section 14.3

How Modern C, Third Edition covers it

How deep it goes
Explains wchar_t, conversion functions, parsing state, locale dependence, and implementation portability checks.
Examples
Uses mbsrtowcs, mbrtowc, locale switching, and Unicode box-drawing character literals.
What it assumes
Assumes familiarity with C strings and introduces multibyte parsing, locales, Unicode code points, and wchar_t.
What you can do after
Apply mbsrtowcs and mbrtowc to convert multibyte input into wchar_t values while tracking parsing state.
How it connects
Connects wchar_t with multibyte strings, mbstate_t, locale, wchar.h, Unicode, and ISO 10646.

Also explained in

Compare how 2 books explain wide character →

Related concepts

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