prasun (prasun) wrote in cprogramming,
prasun
prasun
cprogramming

SIGFPE

What's the deal with SIGFPE?
I tried to install a signal handler to catch things like divide-by-zero, or sqrt(-1), but no SIGFPE is raised - on cygwin, sparc, ppc64. I tried to search this on google, but could not find anything useful.
What is the way to handle this? In C. Portably.
[pratn@ps00 ~]$ cat fpe.c
/*
 * Filename: fpe.c
 * Author:   prasun
 * Created:  Wed Feb 28 19:15:35 2007
 * $Id$
 */

#include <stdio.h>
#include <signal.h>
#include <math.h>
#include <string.h>

void fpe (int x)
{
  fprintf (stderr"Error occurred %d\n"x);
  return ;
}

int main ()
{
  float xy;
  struct sigaction sa;
  memset (&sa0sizeof (struct sigaction));
  sa.sa_handler = fpe;
  sigaction (SIGFPE, &sa0);
  sa.sa_flags = SA_SIGINFO | SA_NODEFER;
  x = -1;
  y = 0;
  printf ("%f\n", (x/y));
  return 0;
}
/* vim: set tw=80 ts=2 sw=2 expandtab: */
[pratn@ps00 ~]$ uname -p
ppc64
[pratn@ps00 ~]$ gcc -Wall -g fpe.c
[pratn@ps00 ~]$ ./a.out
-inf
[pratn@ps00 ~]$
  • Post a new comment

    Error

    default userpic
  • 17 comments