The way to make wchar_t
be 16 bits with clang (or gcc) is to
pass the compiler option -fshort-wchar
(not -fshort-char
).
This is a rather drastic measure, however, as it may break code that
calls the Standard Library or 3rd party libraries passing wchar_t
data. Note
that by default wchar_t
is 32 bits for gcc and clang regardless of whether the
compiler targets 32-bit or 64-bit systems. In this respect they
conform with the C Standard 7.17/2 which requires wchar_t
to be:
an integer type whose range of values can represent distinct codes for all members of the largest extended character set specified among the supported locales
As you are invoking clang++
I presume you are compiling C++ source.
If you simply require a character type that is 16 bits wide, and can compile
with the option -std=c++11
, the core language offers you char16_t
, which
is suitable for storing any UTF-16 character. (And should you wish to
be able to store any UTF-32 character, char32_t
will do).