I'm using a Microsoft C++ compiler (non-managed), and I assume that __int64
is a MS-specific type. My target platform is 32-bit x86, not x64. Is there any way that I can detect overflow after an addition of two __int64
types?
Asked
Active
Viewed 21 times
0
-
Not a duplicate. __int64 is not a native type of x86. It must be an intrinsically wrapped type, such as LARGE_INTEGER. I'm specifically targeting x86 and using __int64. – Lemming Oct 23 '15 at 04:56
-
A quick web search turned this up which seems like a good explanation: http://eli.thegreenplace.net/2010/10/21/64-bit-types-and-arithmetic-on-32-bit-cpus – Jonathan Potter Oct 23 '15 at 05:29
-
Yes, it is a duplicate. C and C++ unfortunately both lack any way to access the CPU's carry / overflow flags directly, so you have to work around it like the answers in the linked question are doing. All the normal techniques for detecting overflow work whether `__int64` operations are being emulated with multiple instructions or not. 64bit addition on x86-32 is done with `add / adc` (where adc is add-with-carry). Having the `add` produce a carry isn't relevant to whether the full 64bit op overflowed or not. In asm you could just check for carry (or overflow for signed) after `adc`. – Peter Cordes Oct 23 '15 at 10:09