Site Tools


wiki:stdmchar.h

Table of Contents

stdmchar.h

The older Unicode headers in C (<wchar.h>, <uchar.h>) have a common problem: they do not tell you how much output buffer space a conversion will need, they do not handle malformed input gracefully, and they do not support transcoding between arbitrary encodings. stdmchar.h is a proposed C header (part of the C2y/C3x standardisation effort) designed to fix this with a cleaner, safer API.

The proposal includes functions like mbrtoc8 (multibyte to UTF-8 code unit) and c8rtomb (UTF-8 to multibyte), along with higher-level transcoding utilities. The intent is to give C a first-class, encoding-correct Unicode story that does not depend on POSIX extensions like iconv or platform-specific APIs.

As of C23, <stdmchar.h> is not yet in the standard. It has been discussed in the WG14 C standardisation committee but compilers do not ship it yet. For now, the C11/C17 approach for Unicode transcoding remains <uchar.h> with mbrtoc16/mbrtoc32 and their inverses. Code that needs iconv-style encoding conversion today typically uses the POSIX iconv API or a library like libunistring.

When (and if) standardised, the practical benefit will be portable code for converting between UTF-8 and the platform locale encoding, written once and compiled anywhere without relying on extensions.

wiki/stdmchar.h.md · Last modified: by 127.0.0.1