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
You can use the macros
__WCHAR_MAX__
__WCHAR_TYPE__
They are defined by gcc. You can check their value with echo "" | gcc -E - -dM
As the value of __WCHAR_TYPE__
can vary from int
to short unsigned int
or long int
, the best for your test is IMHO to check if __WCHAR_MAX__
is above 2^16.
#if __WCHAR_MAX__ > 0x10000
typedef ...
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With