conflicts: definition of wchar_t string in C++ standard and Windows implementation?

前端 未结 2 806
走了就别回头了
走了就别回头了 2021-01-18 05:53

From c++2003 2.13

A wide string literal has type “array of n const wchar_t” and has static storage duration, whe

2条回答
  •  不知归路
    2021-01-18 06:02

    The standard requires that wchar_t be large enough to hold any character in the supported character set. Based on this, I think your premise is correct -- it is wrong for VC++ to represent the single character \U000E0005 using two wchar_t units.

    Characters outside the BMP are rarely used, and Windows itself internally uses UTF-16 encoding, so it is simply convenient (even if incorrect) for VC++ to behave this way. However, rather than "banning" such characters, it is likely that the size of wchar_t will increase in the future while char16_t takes its place in the Windows API.

    The answer you linked to is somewhat misleading as well:

    On Linux, a wchar_t is 4-bytes, while on Windows, it's 2-bytes

    The size of wchar_t depends solely on the compiler and has nothing to do with the operating system. It just happens that VC++ uses 2 bytes for wchar_t, but once again, this could very well change in the future.

提交回复
热议问题