Search code examples
c++typesnamingsuffix

Why are type keywords ended with "_t" suffix?


I understand that size_t has _t suffix since its alias/typedef. However I can't understand for what reason char16_t, char32_t and wchar_t contains _t suffix.


Solution

  • For wchar_t:

    In C++, wchar_t is a distinct fundamental type (and thus it is not defined in <cwchar> nor any other header).

    In C, this is a typedef of an integral type.

    For char16_t and char32_t, defined in <cuchar>/uchar.c:

    In C, this header defines two macros: char16_t and char32_t, which map to unsigned integral types of the appropriate size (the same as uint_least16_t and uint_least32_t, respectively).

    In C++, char16_t and char32_t are fundamental types (and thus this header does not define such macros in C++).

    So, in both cases, even though they are fundamental types in C++, they keep the _t for compatibility with C, where they were typedefs or macros.