This is interesting: With the fprintf
commented out, the compiler has determined that the calculated result: d = b/c
is an unused local expression and can be optimized away.
Clearly though, it is not side-effect free in its execution, but the compiler can't determine anything about the runtime environment at this stage. I'm surprised that static analysis doesn't pick this up as a warning (at least) in a modern compiler.
@vonbrand is right. You got lucky with what you're doing in the (asynchronous) signal handler.
Edit: when you say "signal_handler keeps calling", do you mean it's repeating indefinitely? If so, there could be issues with underlying system calls restarting. Try: siginterrupt(SIGFPE, 1);
(assuming it's available).