I am trying to capture a floating point overflow in C. Here is what I tried
#define _GNU_SOURCE
#include <fenv.h>
#include <signal.h>
#include <stdio.h>
void catch_overflow (int sig) {
printf ("caught division by zero\n");
signal (sig, catch_overflow);
}
int main(void) {
feenableexcept(FE_DIVBYZERO);
signal (FE_DIVBYZERO, catch_overflow);
float a = 1., b = 0.; float c = a/b; return 0; }
I expected to see the message "caught division by zero", but I get a message about the core dump "Floating point exception (core dumped)". How can I change the program to get the message "caught division by zero"?
Thanks.
source
share