简体   繁体   中英

Why is it called 'wchar_t' and not simply 'wchar'?

I've often wondered why C++ went with the name wchar_t instead of simply wchar , and I've never been able to find an answer. Search engines are no help because they think I'm asking about Windows' WCHAR type. Any ideas?

这是来自C的遗产,其中wchar_ttypedef ,而typedef在C标准库中具有该后缀。

The C standard library has used the _t suffix for many of the types that are defined in the library (as opposed to the types that are baked into C itself as keywords).

For example, there's time_t , wchar_t , uint32_t , size_t , ptrdiff_t , div_t , etc.

Of interest (to me anyway) is that the C standard doesn't reserve names of that form for itself. The C standard does indicate that names that start with " str ", " mem ", and a few other prefixes might be added to the standard in the future, but it doesn't do the same with names that end in " _t " - except that names that start with " int " or " uint " and end with " _t " might be added to <stdint.h> in the future. However, POSIX does reserve all names that end in " _t ".

I think this was a 'phase' in the growing up of C and C++. The need for some new types was felt but adding new keywords is always disputed. Some code was already using wchar , far less code would have used wchar_t . Note that size_t and diff_t are of the same era.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM