Skip to content

Instantly share code, notes, and snippets.

@stassats
Created September 5, 2019 23:45
Show Gist options
  • Save stassats/3b3b4ba47295a9276c907050f3fb7bf8 to your computer and use it in GitHub Desktop.
Save stassats/3b3b4ba47295a9276c907050f3fb7bf8 to your computer and use it in GitHub Desktop.
#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