加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

哪个C演员类型是C演员相当于

发布时间:2020-12-16 10:24:10 所属栏目:百科 来源:网络整理
导读:我猜C只是一个重新解释,并且位模式保持原样. 我试图理解当我将更宽的有符号值转换为更窄的有符号值时会发生什么.是保留符号,还是简单地将较窄宽度中的值解释为带符号值. 谢谢你的帮助. 编辑 – 这是针对C99编译的c代码.问题不在于c编译器将使用粗糙的旧样式
我猜C只是一个重新解释,并且位模式保持原样.

我试图理解当我将更宽的有符号值转换为更窄的有符号值时会发生什么.是保留符号,还是简单地将较窄宽度中的值解释为带符号值.

谢谢你的帮助.

编辑 – 这是针对C99编译的c代码.问题不在于c编译器将使用粗糙的旧样式转换,而是如果有什么定义C的作用.

解决方法

如果你只关心C,你真的不需要询问C,但在你的例子中,C和C仍然做大部分相同的事情;

C说这些完整的转换:

If the destination type is signed,the value is unchanged if it can be represented in the destination type (and bit-field width); otherwise,the value is implementation-defined.

C99说这些积分转换:

Otherwise,the new type is signed and the value cannot be represented in it; either the
result is implementation-defined or an implementation-defined signal is raised.

如果可能的话,将较大的整数值转换为较小的有符号整数值将产生相同的值,否则给出实现定义(即,非可移植)行为.

§5.4/ 4州

The conversions performed by

  • a const_cast (5.2.11),
  • a static_cast (5.2.9),
  • a static_cast followed by a const_cast,
  • a reinterpret_cast (5.2.10),or
  • a reinterpret_cast followed by a const_cast,

can be performed using the cast notation of explicit type conversion.

[…]

If a conversion can be interpreted in more than one of the ways listed above,the interpretation that
appears first in the list is used,even if a cast resulting from that interpretation is ill-formed.

定义C使其与C兼容;也就是说,C强制转换将在C中执行与在C中相同的操作.这意味着C中的强制转换符号实际上根据之间的类型执行不同的操作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读