Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

terminology

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?

like image 847
Cogwheel Avatar asked Sep 21 '09 21:09

Cogwheel


2 Answers

That's a legacy from C, where wchar_t is a typedef, and typedefs have that suffix in the C Standard Library.

like image 164
Nemanja Trifunovic Avatar answered Nov 01 '22 18:11

Nemanja Trifunovic


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".

like image 12
Michael Burr Avatar answered Nov 01 '22 19:11

Michael Burr