My multithreaded native C++ application throws INEXACT Floating Point exceptions (FPE) after I added code for one thread to access a property in Windows Management Information (WMI) via the COM interface (using CoInitalize and related functions). Nowhere in this added code (that I know of) is there any explicit use of arithmetic. It simply retrieves a byte value from WMI.
In fact, the exception occurs not in WMI but in another unrelated part of the thread where indeed INEXACT floating operations do take place. But if I change the execution flow to skip the WMI code, those very same code blocks with the floating point operations do not generate exceptions even when manipulating the same numeric values.
I tried to block the exceptions by doing the following:
- Verified that original floating Point Model is /fp:precise.
- Explicitly set the /fp:except- compiler option to disable FPE exceptions
The above had no effect--exceptions continued.
- Inserted the _clearfp() followed by _controlfp_s() functions which clear and mask the FP exceptions before attempting any floating point operation.
This blocked the exceptions. Good.
However this introduces the burden of having to remember to preserve and apply this special treatment to all places where floating point operations are done. Not good.
Is there a way we can make the disabling option (i.e. /fp:except-) in Visual Studio stick? If not, is there another global option or way that would disable floating point exceptions without having to identify and protect every floating point operation with clearfp/controlfp?