[Cfp-interest] draft of syntax discussion for C committee

Fred J. Tydeman tydeman at tybor.com
Tue Jun 10 17:53:35 PDT 2014


On Tue, 10 Jun 2014 14:48:54 -0700 (PDT) David Hough CFP wrote:
>
>> What is the interaction between this idea and
>a signal handler for SIGFPE?
>
>Does anything in C require that enabling IEEE 754 traps cause a SIGFPE?
>That's the way it often works, but I don't think it's mandatory.

That was the intent.

C11

7.12.1#1  [Treatment of <math.h> error conditions]
Each function shall execute as if it were a single operation 
without raising SIGFPE and without generating any of the
floating-point exceptions ''invalid'', ''divide-by-zero'', 
or ''overflow'' except to reflect the result of the function.

H.3.1#3   [LIA-1 Notification]
C's SIGFPE (for traps) and FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW, 
FE_UNDERFLOW (for indicators) can provide LIA-1 notification.

#4
Default handling of SIGFPE can provide trap-and-terminate behavior, 
except for those LIA1 operations implemented by math library 
function calls. User-provided signal handlers for SIGFPE allow for trap-
and-resume behavior with the same constraint.

H.3.1.2#3
C does require that SIGFPE be the signal corresponding to LIA-1 
arithmetic exceptions, if there is any signal raised for them.


J.5.17#1  [Common extensions]
Functions declared in <complex.h> and <math.h> raise SIGFPE to 
report errors instead of, or in addition to, setting errno or 
raising floating-point exceptions (7.3, 7.12).


>It's not possible to write a portable SIGFPE handler that does anything
>more than abort.    The low-level interface to the operating system
>and hardware should be the job of the compiler and run time library,
>not the application writer.     A SIGFPE handler might well be
>part of that hidden implementation.     However it's complicated because
>SIGFPE is often used for other kinds of exceptions, like integer division
>by zero.


---
Fred J. Tydeman        Tydeman Consulting
tydeman at tybor.com      Testing, numerics, programming
+1 (775) 287-5904      Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.



More information about the Cfp-interest mailing list