Why does wcwidth return -1 with a sign that I can print on the terminal?

c, printing, unicode, widechar

Solution

Most likely U+0524 was not a valid character when your libc character database was created. It was added in Unicode 5.2. Your font may include the character already, but `wcwidth` does not look at which font is used.

Problem

Why does here `wcwidth` return "-1" (not a printable wide character) width "Ԥ" (0x0524)? ``` #include <stdio.h> #include <wchar.h> #include <locale.h> int wcwidth(wchar_t wc); int main() { setlocale(LC_CTYPE, ""); wchar_t wc1 = L'合'; // 0x5408 int width1 = wcwidth(wc1); printf("%lc - print width: %i\n", wc1, width1); wchar_t wc2 = L'Ԥ'; // 0x0524 int width2 = wcwidth(wc2); printf("%lc - print width: %i\n", wc2, width2); return 0; } Output: 合 - print width: 2 Ԥ - print width: -1 ```

Original source