当超过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:
<一个href="http://stackoverflow.com/questions/199333/best-way-to-detect-integer-overflow-in-cc">http://stackoverflow.com/questions/199333/best-way-to-detect-integer-overflow-in-cc
许多用于32位溢出的技术chacking适用于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屋!