I tried to study signal processing in C when I discovered strange behavior.
When x / = y; performed in the context of the main function performed by the signal handler. But when the same function executable in some handler (bad_func) is ignored, however, the signal handler for SIGFPE is already installed.
Q: Why was SIGFPE not captured by the function of my global signal handler, even _control87 was called?
(MS VC 2010):
#include "stdafx.h" #include <stdlib.h> #include <stdio.h> #include <signal.h> #include <setjmp.h> #include <float.h> jmp_buf g_jb_MainFunc; void hook_zd (int i) { printf("Result :%i\n",i); longjmp(g_jb_MainFunc, 5); } void bad_func(void) { double x = 0., y = 0.; puts("hello1"); //abort(); x /= y; puts("bye1"); } int main(int argc, char* argv[]) { double x = 0., y = 0.; signal(SIGFPE, hook_zd); signal(SIGABRT, hook_zd); puts("hello"); _control87(0, _MCW_EM ); int res; if (! (res = setjmp(g_jb_MainFunc))) { //abort(); //x /= y; bad_func(); } else { printf("Jumped here from: %i\n",res); } puts("bye"); return 0; }
source share