如何关闭整数溢出保护? [英] How can integer overflow protection be turned off?

查看:115
本文介绍了如何关闭整数溢出保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的默认Rust启用了整数溢出保护,并在溢出时暂停执行中的程序。大量算法需要溢出才能正常工作(SHA1,SHA2等)

My default Rust has integer overflow protect enabled, and will halt a program in execution on overflow. A large number of algorithms require overflow to function correctly (SHA1, SHA2, etc.)

推荐答案

使用 包装 类型,或直接使用包装功能。这些禁用溢出检查。 Wrapping 类型允许您像往常一样使用普通运算符。

Use the Wrapping type, or use the wrapping functions directly. These disable the overflow checks. The Wrapping type allows you to use the normal operators as usual.

此外,当您编译代码时,释放模式(例如使用货物构建--release ),省略溢出检查以提高性能。不要依赖于此,使用上面的类型或函数,以便代码甚至可以在调试版本中工作。

Also, when you compile your code in "release" mode (such as with cargo build --release), the overflow checks are omitted to improve performance. Do not rely on this though, use the above type or functions so that the code works even in debug builds.

这篇关于如何关闭整数溢出保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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