这个问题好像有点似是而非。常用的32位系统下的c的int 都是32bits,也就是说
int b = negative or positive value
uint a = n + (uint)b; //could be an overflow
uint c = n + b; //could be an overflow, too
a == c
相似地,64位和16位系统下c的int 是64/16bits,可以推导出同样的结果。当然,如果32bits system的int 定义为16bit或者64 bits system 的int 定义为32bits,就会有帅哥提出的问题了。这种情况并不常见。
最初由 mooncake 发布
这个问题好像有点似是而非。常用的32位系统下的c的int 都是32bits,也就是说
int b = negative or positive value
uint a = n + (uint)b; //could be an overflow
uint c = n + b; //could be an overflow, too
a == c
相似地,64位和16位系统下c的int 是64/16bits,可以推导出同样的结果。当然,如果32bits system的int 定义为16bit或者64 bits system 的int 定义为32bits,就会有帅哥提出的问题了。这种情况并不常见。