There are __builtin_add_overflow
, __builtin_sub_overflow
and __builtin_mul_overflow
, but there is no __builtin_div_overflow
function in gcc.
It will overflow if you divide INT_MIN
by -1.
Now I have to write some ugly ifs to check it by myself.
where is the question? Write this function yourself and you will avoid ugly
if
s in your app codeMaybe this is better to ask on the gcc mailing list?
stackoverflow.com/questions/30394086/integer-division-overflows has a few functions that do the overflow check
Is there a processor that has a division instruction that sets overflow? x86 raises a divide exception. Arm doesn’t report overflow, nor does MIPS. The intrinsic likely doesn’t exist because no processor supports it.