c++ - Gcc:强制编译器默认使用 unsigned char

标签 c++ gcc char unsigned

由于当 unsigned 限定符不存在时,C++ 中 char 的性质是编译器相关的,是否有一个参数我可以传递给 GCC < strong>强制将所有char编译为unsigned?

最佳答案

您正在寻找的标志是 -funsigned-char

来自 the documentation :

-funsigned-char

Let the type char be unsigned, like unsigned 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.

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.

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

Let the type char be signed, like signed 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.

影响chartypes like wchar_t are unaffected .

关于c++ - Gcc:强制编译器默认使用 unsigned char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20518527/

相关文章:

c++ - inotify递归怎么做呢?

c++ - 解决浮点舍入问题 C++

c++ - GCC 构建问题 (#include_next limits.h)

c++ - 编译器在 GCC 和 MSVC 中生成析构函数和警告

perl - 如何在使用 XS 的 Perl 程序中使用 Ada 模块?

c++ - 字符串到 const char*

c++ - 在 C/C++ 中创建 Windows NTFS 目录连接时出现问题

c++ - 我可以在特定部分中放置完整的命名空间吗?

c# - 将 wchar_t 转换为 Char

java - 计算 ArrayList 中一系列字符串中出现的某个字母的数量