在C前pression,其中unsigned int类型,并签署INT是present,哪种类型将被提升到什么类型的? [英] In a C expression where unsigned int and signed int are present, which type will be promoted to what type?

查看:142
本文介绍了在C前pression,其中unsigned int类型,并签署INT是present,哪种类型将被提升到什么类型的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于C语言标准数据类型提升规则查询。
C99的说:

I have a query about data type promotion rules in C language standard. The C99 says that:

ç整数促销活动也需要,如果一个int可以重新present原始类型的所有值,该值被转换为int;否则,它被转换为unsigned int类型。

我的问题是C语言的前pression其中 unsigned int类型符号int 是的情况下, present,哪种类型将被提升到什么类型的?

My questions is in case of a C language expression where unsigned int and signed int are present, which type will be promoted to what type?

例如。 INT 不能重新present的 unsigned int类型(数值大于大的所有值MAX_INT 值),而 unsigned int类型不能重新present的-ve的值,那么什么类型会提升到什么在这种情况下?

E.g. int cannot represent all the values of the unsigned int (values larger than MAX_INT values) whereas unsigned int cannot represent the -ve values, so what type is promoted to what in such cases?

推荐答案

我认为下面回答你的问题:

I think the following answers your question:

6.3.1.3符号和无符号整数

1 :当整数类型的值是
  转换到另一个整数型
  比_Bool其它,如果该值可
  再由新型psented $ P $,它是
  不变。

1 When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.

2 ,否则,如果新
  类型是无符号,值
  通过反复增加或转换
  减去比最大多一个
  值可以在被重新presented
  新型直到该值在
  范围内新的类型。

2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.

3 ,否则,
  新的类型是有符号和价值
  不能在它psented重新$ P $;或
  其结果是实现定义
  或实现定义的信号
  提高。

3 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.

这篇关于在C前pression,其中unsigned int类型,并签署INT是present,哪种类型将被提升到什么类型的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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