MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Standard C Library Functions                           sigfpe(3C)



NAME
     sigfpe - signal handling for specific SIGFPE codes

SYNOPSIS
     #include 
     #include 

     sigfpehandlertype sigfpe(sigfpecodetype code,
          sigfpehandlertype hdl);


DESCRIPTION
     The sigfpe() function allows signal handling to be specified
     for  particular  SIGFPE codes.  A call to sigfpe() defines a
     new handler hdl for a particular SIGFPE code and returns the
     old  handler as the value of the function sigfpe(). Normally
     handlers are specified as pointers to functions; the special
     cases  SIGFPEIGNORE, SIGFPEABORT, and SIGFPEDEFAULT allow
     ignoring, dumping core using abort(3C), or default  handling
     respectively.   Default  handling  is  to  dump  core  using
     abort(3C).


     The code argument is usually one of the five IE754-related
     SIGFPE codes:

       FPEFLTRES   fpinexact - floating-point inexact result
       FPEFLTDIV   fpdivision - floating-point division by zero
       FPEFLTUND   fpunderflow - floating-point underflow
       FPEFLTOVF   fpoverflow - floating-point overflow
       FPEFLTINV   fpinvalid - floating-point invalid operation



     Three steps are required  to  intercept  an  IE754-related
     SIGFPE code with sigfpe():

         1.   Set up a handler with sigfpe().

         2.   Enable the relevant IE754 trapping capability  in
              the  hardware,  perhaps  by using assembly-language
              instructions.

         3.   Perform a floating-point operation  that  generates
              the intended IE754 exception.


     The sigfpe() function never changes floating-point  hardware
     mode  bits  affecting  IE754 trapping.  No IE754-related
     SIGFPE signals will be generated unless those hardware  mode
     bits are enabled.




SunOS 5.11           Last change: 4 May 2004                    1






Standard C Library Functions                           sigfpe(3C)



     SIGFPE signals can be handled using  sigfpe(),  sigaction(2)
     or  signal(3C). In a particular program, to avoid confusion,
     use only one of these interfaces to handle SIGFPE signals.

EXAMPLES
     Example 1 Example Of A User-Specified Signal Handler


     A user-specified signal handler might look like this:


       #include 
       #include 
       #include 
       /*
       * The samplehandler prints out a message then commits suicide.
       */
       void
       samplehandler(int sig, siginfot *sip, ucontextt *uap) {
            char *label;
               switch (sip->sicode) {
            case FPEFLTINV: label = "invalid operand"; break;
            case FPEFLTRES: label = "inexact"; break;
            case FPEFLTDIV: label = "division-by-zero"; break;
            case FPEFLTUND: label = "underflow"; break;
            case FPEFLTOVF: label = "overflow"; break;
            default: label = "???"; break;
            }
            fprintf(stderr,
               "FP exception %s (0x%x) occurred at address %p.\n",
               label, sip->sicode, (void *) sip->siaddr);
            abort();
       }



     and it might be set up like this:


       #include 
       #include 
       #include 
       extern void samplehandler(int, siginfot *, ucontextt *);
       main(void) {
             sigfpehandlertype hdl, oldhandler1, oldhandler2;
       /*
        * save current fpoverflow and fpinvalid handlers; set the new
       * fpoverflow handler to samplehandler() and set the new
       * fpinvalid handler to SIGFPEABORT (abort on invalid)
       */
           hdl = (sigfpehandlertype) samplehandler;
           oldhandler1 = sigfpe(FPEFLTOVF, hdl);



SunOS 5.11           Last change: 4 May 2004                    2






Standard C Library Functions                           sigfpe(3C)



           oldhandler2 = sigfpe(FPEFLTINV, SIGFPEABORT);
           ...
       /*
        * restore old fpoverflow and fpinvalid handlers
        */
            sigfpe(FPEFLTOVF, oldhandler1);
            sigfpe(FPEFLTINV, oldhandler2);
       }


FILES
     /usr/include/floatingpoint.h




     /usr/include/siginfo.h




ATRIBUTES
     See attributes(5) for descriptions of the  following  attri-
     butes:



     
           ATRIBUTE TYPE               ATRIBUTE VALUE       
    
     MT-Level                     Safe                        
    


SEE ALSO
     sigaction(2),    abort(3C),    signal(3C),    attributes(5),
     floatingpoint.h(3HEAD)

DIAGNOSTICS
     The sigfpe() function returns (void(*)())-1 if code  is  not
     zero or a defined SIGFPE code.














SunOS 5.11           Last change: 4 May 2004                    3



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™