g++ (MinGW) 无法使用选项 -fshort-wchar 将 wchar_t* 转换为 unsigned Short*
我正在将 C++ 项目从 VisalStudio 移植到 GCC/MinGw。
原始项目使用编译器标志/Zc:wchar_t-,它将类型wchar_t定义为无符号短整型(应为2字节)。 现在,当我使用 g++ 和选项 -fshort-wchar 进行编译时。根据文档,此选项还应将 wchar_t 定义为无符号短。
现在有一个
void myfuncExample(short unsigned int*)
使用 wchar_t* 变量调用的函数,该变量应该可以转换为无符号的 Short*。
但是,编译时出现此错误:
error: invalid conversion from 'wchar_t*' to 'short unsigned int*' [-fpermissive]
myfuncExample(buf);
^~~
为什么不能转换?如果我删除 -fshort-wchar 选项,错误是相同的。看起来 g++ 忽略了这个选项。有什么建议吗?
I am porting a C++ Project from VisalStudio to GCC/MinGw.
The original project uses the compiler flag /Zc:wchar_t-, which defines the type wchar_t as an unsigned short (should be 2 bytes).
Now when I compile with g++ and the option -fshort-wchar. According to the documentation this option should also define wchar_t as an unsigned short.
Now there is a function
void myfuncExample(short unsigned int*)
which is called with an wchar_t* variable, which should be castable to an unsigned short*.
However, when compiling I get this error:
error: invalid conversion from 'wchar_t*' to 'short unsigned int*' [-fpermissive]
myfuncExample(buf);
^~~
Why can it no be converted? If i remove the -fshort-wchar option, the error is the same. It seems like g++ is ignoring the option. Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-fshort-wchar
将sizeof(wchar_t)
设置为 2(这已经是 Windows 上的默认值,与其他地方的 4 不同)。它不会使
wchar_t
与unsigned Short
具有相同的类型(即使它们具有相同的大小和符号)。您需要修复代码。
-fshort-wchar
setssizeof(wchar_t)
to 2 (which is already the default on Windows, unlike 4 elsewhere).It doesn't make
wchar_t
the same type asunsigned short
(even though they will have the same size and signedness).You'll need to fix the code.