码迷,mamicode.com
首页 > 其他好文 > 详细

Unintended sign extension

时间:2017-04-15 15:44:48      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:har   explicit   eth   pre   文章   between   eve   mon   result   

 

 

符号扩展包括:

  1. Integral promotion

    charshort, enumerated type, or bit-field, whether signed or unsigned, can be used in any expression that calls for an int. If an int can hold all possible values of the original type, the value is converted to an int. Otherwise, it is converted to an unsigned int.

  2. Conversion between signed and unsigned integers

    When a negative signed integer is promoted to an unsigned integer of the same or larger type, it is first promoted to the signed equivalent of the larger type, then converted to the unsigned value.

 

修复方法:强转

To fix unintended sign extension problems, you must use explicit casting to achieve the intended results.

 

关于“无意的符号扩展”,这里有篇文章讲的很详细

http://docs.oracle.com/cd/E19253-01/816-5138/convert-2/index.html

 

Unintended sign extension

标签:har   explicit   eth   pre   文章   between   eve   mon   result   

原文地址:http://www.cnblogs.com/liuzc/p/6714256.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!