Overflow or carry? If just carry (i.e. unsigned math), this comes to mind:
if ( x > (0xFFFFFFFF & ~y) ) { /* carry */ }
The compiler should optimize out the '0xFFFFFFFF &' if you're compiling for a 32-bit processor.
... or just go with tepples' superior solution :)
UPDATE: These are the best I have come up with for determining signed overflow when adding two signed 32-bit values x and y together:
Code:
/* straight-forward: if signs of x and y match but sign the sum differs */
int overflow = (unsigned) ((x ^ ~y) & ((x + y) ^ x) & 0xFFFFFFFF) >> 31;
/* tricky (too complex to explain) */
long t = y ^ 0x7FFFFFFF;
if ( x > t )
y = ~y;
int overflow = (unsigned) (y & 0xFFFFFFFF) >> 31;