由于当 unsigned
限定符不存在时,C++ 中 char
的性质是编译器相关的,是否有一个参数我可以传递给 GCC < strong>强制将所有char
编译为unsigned
?
最佳答案
您正在寻找的标志是 -funsigned-char
。
来自 the documentation :
-funsigned-char
Let the type
char
be unsigned, likeunsigned char
.Each kind of machine has a default for what
char
should be. It is either likeunsigned char
by default or likesigned char
by default.Ideally, a portable program should always use
signed char
orunsigned char
when it depends on the signedness of an object. But many programs have been written to use plainchar
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.The type
char
is always a distinct type from each ofsigned char
orunsigned char
, even though its behavior is always just like one of those two.
-fsigned-char
Let the type
char
be signed, likesigned 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
; types like wchar_t
are unaffected .
关于c++ - Gcc:强制编译器默认使用 unsigned char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20518527/