wchar_t与GCC有多大? [英] How big is wchar_t with GCC?
问题描述
GCC支持-fshort-wchar将wchar_t从4切换到两个字节。
GCC supports -fshort-wchar that switches wchar_t from 4, to two bytes.
在编译时检测wchar_t大小的最佳方法是什么,我可以正确映射到适当的utf-16或utf-32类型?
至少,直到c ++ 0x被释放,并给我们稳定的utf16_t和utf_32_t typedefs。
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
推荐答案
__WCHAR_MAX__
__WCHAR_TYPE__
它们由gcc定义。您可以使用 echo|检查它们的值gcc -E - -dM
They are defined by gcc. You can check their value with echo "" | gcc -E - -dM
由于 __ WCHAR_TYPE __
的值可以从 int
到 short unsigned int
或 long int
您的测试是IMHO检查 __ WCHAR_MAX __
是否高于2 ^ 16。
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
这篇关于wchar_t与GCC有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!