Visual C++ / Weird behavior after enabling floating-point exceptions (compiler bug ?)

前端 未结 2 979
春和景丽
春和景丽 2021-02-15 17:46

I am struggling to get a reliable way to catch floating points exceptions under Visual Studio (2005 or 2008). By default, under visual studio, floating point exceptions are not

相关标签:
2条回答
  • 2021-02-15 17:54

    Additional information: If you are running 32-bit code on 64-bit windows, and use /arch:SSE2 or other options that enable the SSE2 instruction set, or one of its supersets, you may need to do a more drastic reset.

    With Visual Studio 2015 (and, presumably, later versions), you need to call _fpreset() after floating-point traps generated in the SSE2 registers, rather than just _clearfp(). If you do this with Visual Studio 2013 and earlier, you get a variety of weird problems, caused by the run-time library getting confused.

    0 讨论(0)
  • You have to clear the FPU exception flags in the status word when you catch a floating point exception. Call _clearfp().

    Consider using _set_se_translator() to write an exception filter that translate the hardware exception to a C++ exception. Be sure to be selective, only translate the FPU exceptions.

    0 讨论(0)
提交回复
热议问题