views:

472

answers:

2

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?

+19  A: 

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

Nemanja Trifunovic
Thanks. I hadn't realized it was originally part of C.
Cogwheel - Matthew Orlando
But it happened when C++ was coming up and new ISO standards were hammered out.
Henk Holterman
I know one of C++'s design goals was to remain as compatible with standard C as possible. I can understand their decision, though I can't say I agree with that particular motivation.
Cogwheel - Matthew Orlando
If I remember corrctly it was a two-way street, C imported function-prototypes from C++
Henk Holterman
+2  A: 

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

Michael Burr