1. <small id='imq0P'></small><noframes id='imq0P'>

      • <bdo id='imq0P'></bdo><ul id='imq0P'></ul>

      1. <tfoot id='imq0P'></tfoot>

        <legend id='imq0P'><style id='imq0P'><dir id='imq0P'><q id='imq0P'></q></dir></style></legend>

        <i id='imq0P'><tr id='imq0P'><dt id='imq0P'><q id='imq0P'><span id='imq0P'><b id='imq0P'><form id='imq0P'><ins id='imq0P'></ins><ul id='imq0P'></ul><sub id='imq0P'></sub></form><legend id='imq0P'></legend><bdo id='imq0P'><pre id='imq0P'><center id='imq0P'></center></pre></bdo></b><th id='imq0P'></th></span></q></dt></tr></i><div id='imq0P'><tfoot id='imq0P'></tfoot><dl id='imq0P'><fieldset id='imq0P'></fieldset></dl></div>

        什么时候 uint8_t ≠ unsigned char?

        时间:2023-08-28
        <legend id='AM0jD'><style id='AM0jD'><dir id='AM0jD'><q id='AM0jD'></q></dir></style></legend>
          <tbody id='AM0jD'></tbody>
      2. <small id='AM0jD'></small><noframes id='AM0jD'>

          1. <tfoot id='AM0jD'></tfoot>

              • <i id='AM0jD'><tr id='AM0jD'><dt id='AM0jD'><q id='AM0jD'><span id='AM0jD'><b id='AM0jD'><form id='AM0jD'><ins id='AM0jD'></ins><ul id='AM0jD'></ul><sub id='AM0jD'></sub></form><legend id='AM0jD'></legend><bdo id='AM0jD'><pre id='AM0jD'><center id='AM0jD'></center></pre></bdo></b><th id='AM0jD'></th></span></q></dt></tr></i><div id='AM0jD'><tfoot id='AM0jD'></tfoot><dl id='AM0jD'><fieldset id='AM0jD'></fieldset></dl></div>

                  <bdo id='AM0jD'></bdo><ul id='AM0jD'></ul>
                • 本文介绍了什么时候 uint8_t ≠ unsigned char?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  根据 C 和 C++,CHAR_BIT >= 8.
                  但是每当 CHAR_BIT >8, uint8_t 甚至不能表示为 8 位.
                  它必须更大,因为 CHAR_BIT 是系统上任何数据类型的最小位数.

                  According to C and C++, CHAR_BIT >= 8.
                  But whenever CHAR_BIT > 8, uint8_t can't even be represented as 8 bits.
                  It must be larger, because CHAR_BIT is the minimum number of bits for any data type on the system.

                  在什么样的系统上,uint8_t 可以被合法地定义为 unsigned char 以外的类型?

                  On what kind of a system can uint8_t be legally defined to be a type other than unsigned char?

                  (如果 C 和 C++ 的答案不同,那么我想知道两者.)

                  (If the answer is different for C and C++ then I'd like to know both.)

                  推荐答案

                  如果存在,uint8_t 必须始终与 unsigned char 具有相同的宽度.但是,它不必是相同的类型;它可能是一个不同的扩展整数类型.它也不需要与 unsigned char 具有相同的表示;例如,可以以相反的顺序解释这些位.这是一个愚蠢的例子,但它对 int8_t 更有意义,其中 signed char 可能是补码或符号大小,而 int8_t 是必需的成为二进制补码.

                  If it exists, uint8_t must always have the same width as unsigned char. However, it need not be the same type; it may be a distinct extended integer type. It also need not have the same representation as unsigned char; for instance, the bits could be interpreted in the opposite order. This is a silly example, but it makes more sense for int8_t, where signed char might be ones complement or sign-magnitude while int8_t is required to be twos complement.

                  即使在普通"系统上为 uint8_t 使用非字符扩展整数类型的另一个优势"是 C 的别名规则.字符类型可以给任何东西做别名,这会阻止编译器大量优化同时使用字符指针和指向其他类型的指针的函数,除非 restrict 关键字应用得很好.但是,即使 uint8_t 具有与 unsigned char 完全相同的大小和表示形式,如果实现使其成为独特的非字符类型,则别名规则也不适用于例如,编译器可以假设 uint8_tint 类型的对象永远不能别名.

                  One further "advantage" of using a non-char extended integer type for uint8_t even on "normal" systems is C's aliasing rules. Character types are allowed to alias anything, which prevents the compiler from heavily optimizing functions that use both character pointers and pointers to other types, unless the restrict keyword has been applied well. However, even if uint8_t has the exact same size and representation as unsigned char, if the implementation made it a distinct, non-character type, the aliasing rules would not apply to it, and the compiler could assume that objects of types uint8_t and int, for example, can never alias.

                  这篇关于什么时候 uint8_t ≠ unsigned char?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何检查 C++ 字符串是否为 int? 下一篇:何时使用 std::size_t?

                  相关文章

                • <legend id='Dqgcz'><style id='Dqgcz'><dir id='Dqgcz'><q id='Dqgcz'></q></dir></style></legend>
                    <tfoot id='Dqgcz'></tfoot>

                    <i id='Dqgcz'><tr id='Dqgcz'><dt id='Dqgcz'><q id='Dqgcz'><span id='Dqgcz'><b id='Dqgcz'><form id='Dqgcz'><ins id='Dqgcz'></ins><ul id='Dqgcz'></ul><sub id='Dqgcz'></sub></form><legend id='Dqgcz'></legend><bdo id='Dqgcz'><pre id='Dqgcz'><center id='Dqgcz'></center></pre></bdo></b><th id='Dqgcz'></th></span></q></dt></tr></i><div id='Dqgcz'><tfoot id='Dqgcz'></tfoot><dl id='Dqgcz'><fieldset id='Dqgcz'></fieldset></dl></div>
                      <bdo id='Dqgcz'></bdo><ul id='Dqgcz'></ul>

                      <small id='Dqgcz'></small><noframes id='Dqgcz'>