Why isn't wchar_t widely used in code for Linux / related platforms?

前端 未结 4 1870
迷失自我
迷失自我 2020-12-30 04:22

This intrigues me, so I\'m going to ask - for what reason is wchar_t not used so widely on Linux/Linux-like systems as it is on Windows? Specifically, the Windo

4条回答
  •  轮回少年
    2020-12-30 05:03

    UTF-8, being compatible to ASCII, makes it possible to ignore Unicode somewhat.

    Often, programs don't care (and in fact, don't need to care) about what the input is, as long as there is not a \0 that could terminate strings. See:

    char buf[whatever];
    printf("Your favorite pizza topping is which?\n");
    fgets(buf, sizeof(buf), stdin); /* Jalapeños */
    printf("%s it shall be.\n", buf);
    

    The only times when I found I needed Unicode support is when I had to have a multibyte character as a single unit (wchar_t); e.g. when having to count the number of characters in a string, rather than bytes. iconv from utf-8 to wchar_t will quickly do that. For bigger issues like zero-width spaces and combining diacritics, something more heavy like icu is needed—but how often do you do that anyway?

提交回复
热议问题