使用-fshort-wchar的含义 [英] Implication of using -fshort-wchar

查看:55
本文介绍了使用-fshort-wchar的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS X系统上浏览文件wchar.h时,我发现当未定义__cplusplust且wchar_t的最大大小为2个字节时(通过使用编译器),等效于str函数的wchar_t(如wcscpy,wcscat)中毒了.选项-fshort-wchar).

While going through the file wchar.h on Mac OS X system, I found that wchar_t equivalent of str functions such as wcscpy, wcscat are poisoned when __cplusplust is not defined and max size of wchar_t is of 2 bytes (by using compiler option -fshort-wchar).

对于C程序,如果定义了-fshort-wchar,则似乎不允许此类功能使用.我想知道使用-fshort-wchar时使用wchar_t函数的含义是什么?

It seems that for C program, it does not allow such functions to use if -fshort-wchar is defined. I would like to know that what is the implication of using wchar_t functions when -fshort-wchar is used?

您可能想知道为什么我需要使用-fshort-wchar.因为,我正在移植最初为Windows编写的应用程序,其中wchar_t的大小为两个字节.然后,将wchar_t字符串中保存的数据写入文件,并在两个应用程序之间进行交换.

You may wonder that why I need to use -fshort-wchar. Because, I am porting an application initially written for Windows where size of wchar_t is two bytes. And that data held in wchar_t string is written on the file and also exchanged between two applications.

在不同平台上处理wchar_t可变性的好方法是什么?Windows上的假设是wchar_t为16位.

What is a good way to handle the variability of wchar_t on different platforms? Assumption on Windows is that wchar_t is of 16 bits.

推荐答案

-fshort-wchar 不可用 wchar_t 的正确(32位)定义.可行的情况非常有限,并且可能主要与独立实施/嵌入的东西有关.

-fshort-wchar is not usable if you want to interact with any part of the standard library or third-party library code using the correct (32-bit) definition of wchar_t. The situations where it's viable are very limited and probably pertain mostly to freestanding-implementation/embedded stuff.

在移植您要处理的Windows应用程序的情况下,我认为您应该就位替换以将 wchar_t 的这些用法更改为 WCHAR (您可以自由定义)或 char16_t (由C11定义,您可以在C11之前提供自己的定义).

In the case of porting the Windows application you're dealing with, I think you should just do a seatch-and-replace to change these uses of wchar_t to WCHAR (which you're free to define) or char16_t (defined by C11, and you can supply your own definition pre-C11).

这篇关于使用-fshort-wchar的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆