C / C ++的无符号整数溢出 [英] C/C++ unsigned integer overflow

查看:143
本文介绍了C / C ++的无符号整数溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读有关整数安全的文章。
这里的链接:
<一href=\"http://ptgmedia.pearsoncmg.com/images/0321335724/samplechapter/seacord_ch05.pdf\">http://ptgmedia.pearsoncmg.com/images/0321335724/samplechapter/seacord_ch05.pdf

i'm reading an article about integer security . here's the link: http://ptgmedia.pearsoncmg.com/images/0321335724/samplechapter/seacord_ch05.pdf

在166页,有说:

在无符号运算绝不能溢流,因为一个计算
  结果是不能重新由所得的无符号整数psented $ P $
  类型被减小模数,以比所述较大者的数目
  可再通过将得到的式psented $ P $最大值

A computation involving unsigned operands can never overflow,because a result that cannot be represented by the resulting unsigned integer type is reduced modulo to the number that is one greater than the largest value that can be represented by the resulting type.

这是什么意思? AP preciate答复。

What does it mean? appreciate for reply.

推荐答案

这意味着值环绕。

UINT_MAX + 1 == 0
UINT_MAX + 2 == 1
UINT_MAX + 3 == 2

..等等

为纽带说,这就像模运算符:<一href=\"http://en.wikipedia.org/wiki/Modulo_operation\">http://en.wikipedia.org/wiki/Modulo_operation

As the link says, this is like the modulo operator: http://en.wikipedia.org/wiki/Modulo_operation

这篇关于C / C ++的无符号整数溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆