转化和晋升是一回事吗? [英] Is conversion and promotion the same thing?
问题描述
我不确定升级是否仅意味着将数据类型转换为更大的数据类型(例如,将 short
转换为 int
).
I am not sure if promotion just means converting a data type to a larger data type (for example short
to int
).
或者升级是否意味着将数据类型转换为另一种兼容"数据类型,例如将 short
转换为 int
,这将保持相同的位模式(多余的空间将填充零).转换是否意味着将类似 int
的东西转换为 float
,这将创建完全不同的位模式?
Or does promotion means converting a data type to another "compatible" data type, for example converting a short
to an int
, which will keep the same bit pattern (the extra space will be filled with zeros). And is conversion means converting something like an int
to a float
, which will create a completely different bit pattern?
推荐答案
有两件事被称为促销:积分促销和浮点促销.整数提升是指将整数类型(包括位域和 enum
)转换为更大"的整数类型,而浮点数提升特别是仅将 float
转换为 double 代码>.
There are two things that are called promotions: integral promotions and floating point promotions. Integral promotion refers to integral types (including bitfields and enum
s) being converted to "larger" integral types and floating point promotion is specifically just float
to double
.
这两种促销活动都是更广泛的转化的子集.
Both types of promotions are subsets of a wider range of conversions.
-
char
->int
:积分促销 -
float
->double
:浮点数提升 -
int
->char
:[缩小]转化(不是促销) -
int
->float
:转换 -
const char *
->std :: string
:conversion -
Foo
->Bar
:可能是未定义的转换? - 等
char
->int
: integral promotionfloat
->double
: floating point promotionint
->char
: [narrowing] conversion (not a promotion)int
->float
: conversionconst char*
->std::string
: conversionFoo
->Bar
: possibly undefined conversion?- etc.
这篇关于转化和晋升是一回事吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!