Alex Rivera | Logout

How big is wchar_t with GCC?

Asked 2011-02-02T10:57:24.727
17

GCC supports -fshort-wchar that switches wchar_t from 4, to two bytes.

What is the best way to detect the size of wchar_t at compile time, so I can map it correctly to the appropriate utf-16 or utf-32 type? At least, until c++0x is released and gives us stable utf16_t and utf_32_t typedefs.

#if ?what_goes_here?
  typedef wchar_t Utf32;
  typedef unsigned short Utf16;
#else
  typedef wchar_t Utf16;
  typedef unsigned int Utf32;
#endif
Edit
Report

1 Answer

3

As Luther Blissett said, wchar_t exists independently from Unicode - they are two different things.

If you are really talking about UTF-16 - be aware that there are unicode characters which map to two 16-bit words (U+10000..U+10FFFF, although these are rarely used in western countries/languages).

answered 2011-02-02T12:16:41.910

Your Answer