超过 64 位时的未定义行为 [英] Undefined behavior when exceed 64 bits
问题描述
在我当前的 32 位应用程序中,我通过对 64 位整数进行运算来检查(偶尔)是否溢出.
In my current 32-bit application, I check (very occasionally) for overflow by doing operations on 64-bit integers.
然而,在 64 位系统上似乎没有标准的 128 位整数.有没有一种检查溢出的简单方法,或者一种获取 128 位整数的方法,它适用于所有操作系统和编译器?
However, on 64-bit systems there does not seem to be a standard 128-bit integer. Is there a simple way of checking for overflow, or a way of getting 128-bit integers, which works on all OSes and compilers?
我尝试使用 GMP 作为更通用的解决方案,但它对我的要求来说有点重量级.
I tried using GMP as a more generic solution, but it is a little heavyweight for my requirements.
效率不太重要,没有特定于处理器的 ASM.
Efficiency is not too important, no processor specific-ASM is.
推荐答案
这个问题中的大部分讨论都适用:
Much of the discussion in this question applies:
用于 32 位溢出控制的许多技术也适用于 64 位(并非所有讨论的技术都使用下一个更大的整数类型来处理溢出).
Many of the techniques used for 32-bit overflow chacking apply to 64-bits as well (not all of the techniques discussed use the next larger integer type to handle the overflow).
这篇关于超过 64 位时的未定义行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!