Why there is no __builtin_div_overflow function in gcc?

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.

  • 1

    where is the question? Write this function yourself and you will avoid ugly ifs in your app code

    – 




  • 2

    Maybe this is better to ask on the gcc mailing list?

    – 

  • 2

    stackoverflow.com/questions/30394086/integer-division-overflows has a few functions that do the overflow check

    – 

  • 3

    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.

    – 




Leave a Comment