Unintended sign extension
符号扩展包括:
-
Integral promotion
A
char
,short
, enumerated type, or bit-field, whether signed or unsigned, can be used in any expression that calls for anint
. If anint
can hold all possible values of the original type, the value is converted to anint
. Otherwise, it is converted to anunsigned int
. -
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
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步