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:强制编译器默认使用无符号字符


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01