Why was wchar_t invented?

前端 未结 10 1657
说谎
说谎 2021-01-03 20:15

Why is wchar_t needed? How is it superior to short (or __int16 or whatever)?

(If it matters: I live in Windows world. I don\'t

10条回答
  •  礼貌的吻别
    2021-01-03 21:07

    Except for a small, ISO 2022 japanese minority, wchar_t is always going to be unicode. If you are really anxious you can make sure of that at compile time:

    #ifndef __STDC_ISO_10646__
    #error "non-unicode wchar_t, unsupported system"
    #endif
    

    Sometimes wchar_t is 16bits UCS-2 sometimes 32bits UCS-4, so what? Just use sizeof(wchar_t). wchar_t is NOT meant to be sent to disk nor to the network, it is only meant to be used in memory.

    See also Should UTF-16 be considered harmful? on this site.

提交回复
热议问题