How big is wchar_t with GCC?(GCC 的 wchar_t 有多大?)
问题描述
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 类型定义之前.
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,最好恕我直言,您的测试是检查 __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
这篇关于GCC 的 wchar_t 有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GCC 的 wchar_t 有多大?
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
