Are `char16_t` and `char32_t` misnomers?

前端 未结 3 1668
慢半拍i
慢半拍i 2021-02-07 20:50

NB: I\'m sure someone will call this subjective, but I reckon it\'s fairly tangible.

C++11 gives us new basic_string types

3条回答
  •  有刺的猬
    2021-02-07 21:07

    The naming convention to which you refer (uint32_t, int_fast32_t, etc.) is actually only used for typedefs, and not for primitive types. The primitive integer types are {signed, unsigned} {char, short, int, long, long long}, {as opposed to float or decimal types} ...

    However, in addition to those integer types, there are four distinct, unique, fundamental types, char, wchar_t, char16_t and char32_t, which are the types of the respective literals '', L'', u'' and U'' and are used for alpha-numeric type data, and similarly for arrays of those. Those types are of course also integer types, and thus they will have the same layout at some of the arithmetic integer types, but the language makes a very clear distinction between the former, arithmetic types (which you would use for computations) and the latter "character" types which form the basic unit of some type of I/O data.

    (I've previously rambled about those new types here and here.)

    So, I think that char16_t and char32_t are actually very aptly named to reflect the fact that they belong to the "char" family of integer types.

提交回复
热议问题