Microsoft KB Archive/43391

= INFO: Handling Floating-Point Errors in C =

Article ID: 43391

Article Last Modified on 12/8/2003

-

APPLIES TO

 The C Run-Time (CRT), when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 2.2</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul>

 Microsoft Visual C++ 5.0 Standard Edition</li></ul>

 Microsoft Visual C++ 6.0 Service Pack 5</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q43391

<div class="notice_section">

<div class="summary_section">

SUMMARY
With Microsoft C, floating-point error-handling routines may be written using the signal function; however, &quot;return&quot; should not be used to go back to the calling process. If &quot;return&quot; is used, the floating-point state is left undefined.

Instead, use the setjmp function 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.

WARNING: Neither the setjmp nor longjmp function is compatible with the C++ language.

The sample program on page 296 of the &quot;Microsoft C/C++ Run-time Library Reference&quot; that shipped with Microsoft C/C++ version 7.0 demonstrates the use of setjmp, _fpreset, and longjmp to handle a floating-point error. The online help also provides samples for these functions.

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.

Keywords: kbinfo kbcrt KB43391

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.