uint8_t有可能是一个非字符类型? [英] Can uint8_t be a non-character type?

查看:277
本文介绍了uint8_t有可能是一个非字符类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个答案和附加注释的,的帕维尔Minaev 做的是,在C,唯一的类型到 uint8_t有可typedef定义为<$ C以下几种说法$ C>字符和 unsigned char型。我期待在 C标准的这一草案。

In this answer and the attached comments, Pavel Minaev makes the following argument that, in C, the only types to which uint8_t can be typedef'd are char and unsigned char. I'm looking at this draft of the C standard.


  • 的uint8_t有的presence意味着相应类型的presence中int8_t (7.18。 1P1)。

  • 中int8_t 宽度为8位,没有填充位(7.18.1.1p1)。

  • 通讯类型具有相同的宽度(6.2.5p6),所以 uint8_t有也是8位宽。

  • unsigned char型 CHAR_BIT 位宽(5.2.4.2.1p2和6.2.6.1p3)。

  • CHAR_BIT 至少8(5.2.4.2.1p1)。

  • CHAR_BIT 最多为8,因为无论 uint8_t有 unsigned char型,或者它是一个非 - unsigned char型,非位字段类型,其宽度的倍数 CHAR_BIT (6.2.6.1p4)。

  • The presence of uint8_t implies the presence of a corresponding type int8_t (7.18.1p1).
  • int8_t is 8 bits wide and has no padding bits (7.18.1.1p1).
  • Corresponding types have the same width (6.2.5p6), so uint8_t is also 8 bits wide.
  • unsigned char is CHAR_BIT bits wide (5.2.4.2.1p2 and 6.2.6.1p3).
  • CHAR_BIT is at least 8 (5.2.4.2.1p1).
  • CHAR_BIT is at most 8, because either uint8_t is unsigned char, or it's a non-unsigned char, non-bit-field type whose width is a multiple of CHAR_BIT (6.2.6.1p4).

,我同意,如果 uint8_t有存在,那么它和 unsigned char型具有相同重新presentations:8位值0填充位。这似乎不强迫他们是同一类型(例如,6.2.5p14)。

Based on this argument, I agree that, if uint8_t exists, then both it and unsigned char have identical representations: 8 value bits and 0 padding bits. That doesn't seem to force them to be the same type (e.g., 6.2.5p14).

是不是允许的 uint8_t有的typedef定义为一个扩展的无符号整型(6.2.5p6)具有相同重presentation为 unsigned char型当然,它必须被typedef定义(7.18.1.1p2),并且不能超过无符号的任何标准的无符号整型焦(或字符如果它正好是无符号)​​。这个假设的扩展类型不会是一个字符类型(6.2.5p15),因此将不符合别名访问一个不兼容的类型(6.5p7),这令我的原因对象的编译器作者想要做这样的的事情。

Is it allowed that uint8_t is typedef'd to an extended unsigned integer type (6.2.5p6) with the same representation as unsigned char? Certainly it must be typedef'd (7.18.1.1p2), and it cannot be any standard unsigned integer type other than unsigned char (or char if it happens to be unsigned). This hypothetical extended type would not be a character type (6.2.5p15) and thus would not qualify for aliased access to an object of an incompatible type (6.5p7), which strikes me as the reason a compiler writer would want to do such a thing.

推荐答案

如果 uint8_t有存在,不填充要求意味着 CHAR_BIT 是8。但是,没有根本的原因,我可以找到为什么 uint8_t有不能用的扩展整数类型的定义。而且也不能保证该重新presentations是相同的;例如,这些位可以以相反的顺序PTED间$ P $

If uint8_t exists, the no-padding requirement implies that CHAR_BIT is 8. However, there's no fundamental reason I can find why uint8_t could not be defined with an extended integer type. Moreover there is no guarantee that the representations are the same; for example, the bits could be interpreted in the opposite order.

虽然这看起来愚蠢的,无偿寻常的 uint8_t有,它可以使为有很大的意义中int8_t 。如果一台机器本身使用那些补充或符号/幅度,那么符号字符不适合中int8_t 。但是,它可以使用一个模拟二进制补码提供扩展符号整型中int8_t

While this seems silly and gratuitously unusual for uint8_t, it could make a lot of sense for int8_t. If a machine natively uses ones complement or sign/magnitude, then signed char is not suitable for int8_t. However, it could use an extended signed integer type that emulates twos complement to provide int8_t.

这篇关于uint8_t有可能是一个非字符类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆