INF: Handling Floating-Point Errors in C

ID Number: Q43391

5.00 5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

With Microsoft C versions 5.0 and 5.1, floating-point error-handling

routines may be written using the signal() function; however, "return"

should not be used to go back to the calling process. If "return" is

used, the floating-point state is left undefined.

Instead, use the function setjmp() to save the stack environment

before each section of the calling process code that may potentially

generate a floating-point error. In the error handler, use _fpreset()

to reinitialize the floating-point package and longjmp() to return to

the calling process.

More Information:

The sample program on page 280 of the "Microsoft C Optimizing Compiler

Run-time Library Reference" that shipped with Microsoft C version 5.1

demonstrates the use of setjmp(), _fpreset(), and longjmp() to handle

a floating-point error.

The function setjmp() saves the environment (bp, si, di, sp, and ds

registers) and return address in a buffer. The buffer is used by

longjmp() to restore the environment.

Note: In versions 6.0 and later of Microsoft C, in order to maintain

ANSI compatibility, these functions are now prepended by an underscore

("_"). These functions are now called _signal(), _setjmp(), and

_longjmp(). Sample programs for these functions are located in the

online help in versions 6.0 and later.

Additional reference words: 6.00 6.00a 6.00ax quickc 2.00 2.01 2.50

2.51