Gcc:强制编译器默认使用unsigned char [英] Gcc: force compiler to use unsigned char by default
问题描述
由于C ++中的 char
的性质是编译器依赖的,当 unsigned
限定词不存在时,有一个参数我可以传递给GCC,这将强制所有 char
s编译为 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
-funsigned-char
让类型 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
-fsigned-char
让类型 char
被签名,如 signed char
。
注意,这等价于 -fno-unsigned-char
code> -funigned-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
.
这篇关于Gcc:强制编译器默认使用unsigned char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!