Cogwheel
Cogwheel

Reputation: 23217

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?

Upvotes: 26

Views: 2780

Answers (3)

Henk Holterman
Henk Holterman

Reputation: 273244

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.

Upvotes: 5

Nemanja Trifunovic
Nemanja Trifunovic

Reputation: 24561

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

Upvotes: 35

Michael Burr
Michael Burr

Reputation: 340208

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

Upvotes: 12

Related Questions