⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convert.gml

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 GML
字号:
.pp
Whenever two operands are involved in an operation,
some kind of
.ix 'conversion' 'type'
.ix 'type' 'conversion'
.us conversion
of one or both of the operands may take place.
For example, a
.kw short int
and a
.kw long int
cannot be directly added. Instead, the
.kw short int
must first be converted to a
.kw long int
..ct ,
then the two values can be added.
.pp
Fortunately, C provides most conversions as
.us implicit
operations. Simply by indicating that the two values
are to be added, the C compiler will check their types and
generate the appropriate conversions.
Sometimes it is necessary, however, to be aware of exactly
how C will convert the operands.
.pp
Conversion of operands always attempts to preserve
the value of the operand.
Where preservation of the value is not possible, the compiler will
sign-extend signed quantities and discard the high bits
of quantities being converted to smaller types.
.pp
The rules of type conversions are fully discussed in
the following sections.
.*
.section Integral Promotion
.ix 'integral promotion'
.ix 'promotion' 'integer'
.*
.begnote
.note Rule:
A
.kw char
..ct ,
.kw short int
or
.kw int
bit-field in either of their signed or unsigned forms, or an object
that has an enumerated type, is always converted to an
.kw int
..ct ..li .
If the type
.kw int
cannot contain the entire range of the object being converted, then
the object will be converted to an
.kw unsigned int
..ct ..li .
.endnote
.pp
A
.kw signed
or
.kw unsigned char
will be converted to a
.kw signed int
without changing the value.
.*
.************************************************************************
.*
..if '&target' eq 'PC' or '&target' eq 'PC 370' ..th ..do begin
.shade begin
With &wc286., a
.kw short int
has the same range as
.kw int
..ct ,
therefore a
.kw signed short int
is converted to a
.kw signed int
..ct ,
and an
.kw unsigned short int
is converted to an
.kw unsigned int
..ct ,
without changing the value.
.pp
With &wc386., a
.kw signed
or
.kw unsigned
.kw short int
is converted to an
.kw int
without changing the value.
.shade end
..do end
..if '&target' eq 'PC 370' ..th ..do begin
.shade begin
With &wlooc., a
.kw signed
or
.kw unsigned
.kw short int
is converted to an
.kw int
without changing the value.
.shade end
..do end
.*
.************************************************************************
.*
.pp
These promotions are called the
.ix 'integral promotion'
.ix 'promotion' 'integer'
.us integral promotions.
.*
.section Signed and Unsigned Integer Conversion
.ix 'conversion' 'signed integer'
.ix 'conversion' 'unsigned integer'
.ix 'integer' 'conversion'
.*
.begnote
.note Rule:
.ix 'conversion' 'unsigned integer'
.ix 'unsigned integer conversion'
If an unsigned integer is converted to an integer type of any size,
then, if the value can be represented in the new type, the value
remains unchanged.
.endnote
.pp
If an unsigned integer is converted to a longer type (type with greater
range), then the value will not change.
If it is converted to a type with a smaller range, then provided
the value can be represented in the smaller range, the value will
remain unchanged. If the value cannot be represented, then if
the result type is signed, the result is implementation-defined.
If the result type is
.kw unsigned
..ct ,
the result is the integer modulo (1+the largest unsigned number that
can be stored in the shorter type).
.shade begin
With
..if '&target' eq 'PC' ..th ..do begin
&wc286.,
..do end
..el ..if '&target' eq 'PC 370' ..th .do begin
both &wcboth. and &wlooc.,
..do end
..el ..if '&target' eq '370' ..th ..do begin
&wlooc.,
..do end
unsigned integers are promoted to longer types by extending the
high-order bits with zeros.
They are demoted to shorter types by
discarding the high-order portion of the larger type.
.shade end
.pp
Consider the following examples of 32-bit quantities (
..ct .kw unsigned long int
..ct )
being converted
to 16-bit quantities (
..ct .kw signed short int
or
.kw unsigned short int
..ct ):
..sk 1 c
.if &e'&nobox eq 0 .do begin
.boxdef
..if '&format' eq '7x9' ..th ..do begin
.  .boxcol  6
.  .boxcol 10
.  .boxcol  9
.  .boxcol  6
.  .boxcol  8
..do end
..el ..do begin
.  .boxcol  7
.  .boxcol 13
.  .boxcol 11
.  .boxcol  7
.  .boxcol  9
..do end
.boxbeg
.monoon

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -