signal() with SIGFPE Requires Floating-Point Support

ID: Q72726


The information in this article applies to:


SUMMARY

The signal() function may be used to trap floating-point errors that would normally be fatal for an application. To trap these exceptions, the floating-point library must be linked in and become a part of the .EXE. One way that this can be done is by defining a double and initializing it to "0.0f" in your code.

If floating-point support has not been linked in for some reason and you try to set up a signal handler for SIGFPE (floating-point error), signal() will return SIG_ERR.


MORE INFORMATION

The types of floating-point exceptions that you can trap with the signal() function include the following:

The following sample code attempts to set up a signal handler for SIGFPE without indicating that the floating-point code should be linked in, resulting in the return of SIG_ERR to signal(). Removing the comment corrects the problem.

Sample Code


/* Compile options used:
*/ 

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

void func1(int, int);

void main(void)
{
//   double d = 0.0f;                    // Uncomment for workaround
   if(signal(SIGFPE, func1)==SIG_ERR)
      printf("signal Failed\n");
}

void func1(int i, int j)
{
} 

Additional query words: kbinf 6.00 6.00a 6.00ax 5.00 5.10 7.00 1.00 1.50


Keywords          : kb16bitonly 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: July 28, 1999