0

Why doesn't it give some error like "divide by zero"?

https://code.sololearn.com/cRlOGExVtK7Z/?ref=app

15th Mar 2018, 2:23 PM
Siddharth Garg
Siddharth Garg - avatar
2 Answers
+ 6
Because an INTEGER division by zero generates a CPU floating point exception (FPE) (float's don't -- see note*) Here's what it looks like in an Android (linux) shell, running through a tracing program: # strace ./testcode ... code runs, then SIGNAL:Floating Point Exception... tgkill(12345, 12345, SIGFPE) = 0 --- SIGFPE {si_signo=SIGFPE, si_code=SI_TKILL, si_pid=12345, si_uid=0} --- +++ killed by SIGFPE +++ Floating point exception Capturing FPEs is not standardized and is done differently on each platform, e.g. unistd.h + fpsettrapenable() is supposedly reliably usable... but doesn't work here. Signals (signal.h) worked to catch the exception: https://code.sololearn.com/cu27f4W9E21L/?ref=app One final note, do not return from CPU traps (signals) -- they should be fatal. The state of the program is broken by the signal + undefined, which (in my estimation) is why SoloLearn gives you NO OUTPUT on such events. https://wiki.sei.cmu.edu/confluence/display/c/SIG35-C.+Do+not+return+from+a+computational+exception+signal+handler * FLOAT DIV/0 is well-defined and will returns (on this platform at least): 1.#INF00
15th Mar 2018, 8:11 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Sololearn doesn't print all errors. If you comlile it on your PC it would definitely produce the correct error message
15th Mar 2018, 2:27 PM
Aaron Eberhardt
Aaron Eberhardt - avatar