Gcc: force compiler to use unsigned char by default(Gcc:强制编译器默认使用无符号字符)
问题描述
由于当 unsigned
限定符不存在时,C++ 中 char
的性质是依赖于编译器的,是否有一个参数可以传递给 GCC,它会 强制将所有char
编译为unsigned
?
Since the nature of a char
in C++ is compiler-dependent when the unsigned
qualifier is not present, is there an argument I could pass on to GCC which would force all char
s to be compiled as unsigned
?
推荐答案
你要找的标志是-funsigned-char
.
来自文档:
-funsigned-char
让char
类型是无符号的,如unsigned char
.
Let the type char
be unsigned, like unsigned char
.
每种机器都有一个默认的 char
应该是什么.默认情况下类似于 unsigned char
或默认情况下类似于 signed char
.
Each kind of machine has a default for what char
should be. It is either like unsigned char
by default or like signed char
by default.
理想情况下,可移植程序在依赖于对象的签名时应始终使用 signed char
或 unsigned char
.但是许多程序被编写为使用纯 char
并期望它被签名,或者期望它是未签名的,这取决于它们被编写的机器.此选项及其反选项使您可以使此类程序以相反的默认值运行.
Ideally, a portable program should always use signed char
or unsigned char
when it depends on the signedness of an object. But many programs have been written to use plain char
and expect it to be signed, or expect it to be unsigned, depending on the machines they were written for. This option, and its inverse, let you make such a program work with the opposite default.
类型 char
总是与 signed char
或 unsigned char
中的每一个不同的类型,即使它的行为总是一样那两个.
The type char
is always a distinct type from each of signed char
or unsigned char
, even though its behavior is always just like one of those two.
-fsigned-char
让char
类型被签名,就像signed char
一样.
Let the type char
be signed, like signed char
.
注意,这等价于-fno-unsigned-char
,是-funsigned-char
的否定形式.同样,选项 -fno-signed-char
等效于 -funsigned-char
.
Note that this is equivalent to -fno-unsigned-char
, which is the negative form of -funsigned-char
. Likewise, the option -fno-signed-char
is equivalent to -funsigned-char
.
这只影响char
;wchar_t
等类型不受影响.
This only impacts char
; types like wchar_t
are unaffected.
这篇关于Gcc:强制编译器默认使用无符号字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Gcc:强制编译器默认使用无符号字符
基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01