C中的操作数转换 [英] operand conversion in C

查看:88
本文介绍了C中的操作数转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请阅读本段(来自C99标准的6.3.1.8节):
操作数比较.
如果两个操作数具有相同的类型,则不需要进一步的转换.

否则,如果两个操作数都具有符号整数类型或都具有无符号整数类型,则将具有较小整数转换等级的类型的操作数转换为具有较高等级的操作数的类型.
否则,如果具有无符号整数类型的操作数的秩大于或等于另一个操作数的类型的秩,则具有符号整数类型的操作数将转换为具有无符号整数类型的操作数的类型.

否则,如果带符号整数类型的操作数的类型可以表示无符号整数类型的操作数的所有值,则将无符号整数类型的操作数转换为带符号整数类型的操作数的类型. br/>
否则,两个操作数都将转换为与带符号整数类型的操作数类型相对应的无符号整数类型. "


我们在本段中看到转换一词.
我的问题是这种转换是在编译时还是运行时完成的吗?

please read this paragraph(from section 6.3.1.8 of the C99 standard):
operand comparision.
If both operands have the same type, then no further conversions are required.

"Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank is converted to the type of the operand with greater rank.
Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted to the type of the operand with unsigned integer type.

Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, then the operand with unsigned integer type is converted to the type of the operand with signed integer type.

Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type. "


we see the word conversion in this in this paragraph.
my question is this conversion is accomplished at compile time or runtime?

推荐答案

转换类型的分析显然是在编译时完成的.所有静态类型分析都是在编译时完成的.

实际的转换是在运行时完成的.

但是编译器通常会尝试进行优化,例如编译时常量在编译时进行转换-没有理由在运行时对它们进行转换.

干杯
安迪
The analysis for the kind of conversion is clearly done at compile time. All static type analysis is done at compile time.

The actual conversion is done at runtime.

But the compiler usually tries to optimize, e.g. compile time constants are converted at compile time - no reason to have the conversion done at run time for these.

Cheers
Andi


这篇关于C中的操作数转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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