[英]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. 我经常想知道为什么C ++使用的名称是
wchar_t
而不是简单的wchar
,而且我从来没有找到答案。 Search engines are no help because they think I'm asking about Windows' WCHAR
type. 搜索引擎没有帮助,因为他们认为我在询问Windows的
WCHAR
类型。 Any ideas? 有任何想法吗?
这是来自C的遗产,其中wchar_t
是typedef
,而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). C标准库对库中定义的许多类型使用
_t
后缀(而不是作为关键字烘焙到C本身的类型)。
For example, there's time_t
, wchar_t
, uint32_t
, size_t
, ptrdiff_t
, div_t
, etc. 例如,有
time_t
, wchar_t
, uint32_t
, size_t
, ptrdiff_t
, div_t
等。
Of interest (to me anyway) is that the C standard doesn't reserve names of that form for itself. (无论如何)我感兴趣的是C标准不保留该形式的名称。 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. C标准确实表明将来以“
str
”,“ mem
”和一些其他前缀开头的名称可能会被添加到标准中,但是对于以“ _t
”结尾的名称不会这样做 -除了以“ int
”或“ uint
”开头并以“ _t
”结尾的名称将来可能会被添加到<stdint.h>
中。 However, POSIX does reserve all names that end in " _t
". 但是,POSIX会保留所有以“
_t
”结尾的名称。
I think this was a 'phase' in the growing up of C and C++. 我认为这是C和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
. 有些代码已经使用了
wchar
,使用wchar_t
代码要少得多。 Note that size_t
and diff_t
are of the same era. 请注意,
size_t
和diff_t
属于同一时代。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.