Microsoft KB Archive/243534

= BUG: Optimization Generates Incorrect Results for an Inline Function Returning double =

Article ID: 243534

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q243534



SYMPTOMS
When a method of one class calls, as an input argument, an inline function that creates an object of another class and returns a double, the compiler may generate incorrect results.



CAUSE
This occurs when compiled with the /Ob1 (Only _inline) or /Ob2 (Any Suitable) optimizations turned on.



RESOLUTION
There are two possible ways to work around this problem:
 * Compile the project with the /Ob1 (Only _inline) or /Ob2 (Any Suitable) optimizations turned off.
 * Store the results of the function that is used as an input parameter in a temporary variable. Pass the temporary variable as the argument to the method of the class that returns a double.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The following code demonstrates the problem and the second workaround: // test.cpp // cl /GX /O2 /Ob1 test.cpp
 * 1) include 

class secClass { public: secClass(const char *) {}; ~secClass {}; private: };

class firstClass { public: firstClass {} void setNum(double num) { cout << "The number is " << num << endl; }; };

double getNum(secClass str) {   return 7.0; }

int main(int argc, char* argv[]) {   firstClass f;        cout << "Incorrect Results" << endl; f.setNum(getNum("Test")); //Second workaround. cout << "Correct Results" << endl; double d = getNum("Test"); f.setNum(d); return 0; } The output of the above program is as follows: Incorrect Results The number is 1.84959e-307 Correct Results The number is 7

Keywords: kbbug kbnofix kbcodegen kbcpponly kbcompiler KB243534

-

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

© Microsoft Corporation. All rights reserved.