0

I am working with a .NET 3.5 application in C# that calls some legacy C++ code regularly. I've noticed that calling into the C++ sometimes leads to an "Overflow or underflow arithmetic operation" when I mouse over an Infragistics UltraGrid that has a dropdown list. I've discovered that this only happens when the C++ codes does the following:

Word SavedWord = Default8087CW;
Set8087CW(0x133f); // Disable all fpu exceptions

...

Set8087CW(SavedWord);

If I comment out the last line, I no longer get the error in my .NET application. I haven't noticed any other side effects in the rest of the application. As a quick fix, I would like to leave this line commented out. What are the consequences of disabling FPU exceptions and not resetting the control word?

4
  • Is the value of Default8087CW what the real value was upon entry to your C++ function or is it what the C++ RTL thinks is the default? The two may differ. Commented May 29, 2012 at 18:18
  • @500-InternalServerError, how would I check that? All I've been able to confirm is that the value of Default8087CW upon exit of the C++ code is the same as it was upon entry. Commented May 29, 2012 at 18:25
  • I'm not familiar with how to do this in C++. Isn't there a corresponding Get8087CW() function? Commented May 29, 2012 at 18:33
  • From what I can tell Default8087CW is the equivalent of Get8087CW(). Get8087CW() doesn't actually exist in this version of C++. Reference: docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/… Commented May 29, 2012 at 18:49

2 Answers 2

2

The solution is found here: "StackOverFlowException in WPF when call method from C++ library".

Thanks to Hans Passant for this.

Sign up to request clarification or add additional context in comments.

Comments

0

After testing on other machines, it appears that commenting out the Set8087CW(SavedWord); line only fixes the issue on my machine. There appears to be a bug in my version of Infragistics (8.2.20082.2204). Rolling back to 8.2.20082.1000 fixed the issue.

2 Comments

Hmm, doubtful. There's a lot of code that is not compatible with the changes that the Borland runtime makes to the FPU control word. Any .NET code will be vulnerable. You must have already run into some code like that, considering you already found this snippet in your program. Here's another example: stackoverflow.com/a/8357646/17034
That's a very interesting post, @HansPassant. I've switched back to the newer version of Infragistics and implemented the solution mentioned there. Seems to work. Do you want to add an answer with a reference to that post?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.