Created
September 5, 2019 23:45
-
-
Save stassats/3b3b4ba47295a9276c907050f3fb7bf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <signal.h> | |
#include <setjmp.h> | |
#include <fenv.h> | |
jmp_buf unwind; | |
void handler(int signum) | |
{ | |
printf("sigfpe\n"); | |
longjmp(unwind, 1); | |
} | |
int main() | |
{ | |
double i = 1.0, j; | |
struct sigaction sa; | |
sigemptyset(&sa.sa_mask); | |
sa.sa_handler = handler; | |
sa.sa_flags = SA_NODEFER; | |
sigaction(SIGFPE, &sa, NULL); | |
setjmp(unwind); | |
feenableexcept(FE_DIVBYZERO); | |
for(;;) { | |
j = i / 0.0; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment