BUG: Bad Result If Call Inline Function Twice in Expression

ID: Q135526


The information in this article applies to:


SYMPTOMS

Invalid results may be generated under these conditions:


RESOLUTION

Do not use the above optimizations.

-or-

Assign the return value of one of the function calls to a local variable. Then use the local variable in the expression.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

Sample Code to Reproduce the Problem


/* Compile options needed 32-bit Compiler: /Ob1, or /Ob2, or /Ox
/* Compile options needed 16-bit Compiler: /Ob1g, or /Ob2g, or /Ox
*/ 

#include <stdio.h>

int  nGlobal = 0;

inline int test(int nIn) {
   return  nGlobal = nIn;
}

void main() {
   // This will incorrectly evaluate to true.
   if  (test(1) == test(2))
       printf("test(1) == test(2)\n");
   else
       printf("test(1) != test(2)\n");

   // This will correctly evaluate to false.
   int n = test(2);

   if  (test(1) == n)
       printf("test(1) == test(2)\n");
   else
       printf("test(1) != test(2)\n");
} 

Additional query words: kbVC400bug 8.00c 9.00 9.10 10.00 10.10 10.20


Keywords          : kbCodeGen kbCompiler kbCPPonly kbVC kbVC200bug kbVC210bug kbVC220bug kbVC400bug kbVC410bug kbVC420bug kbVC500bug kbVC600bug 
Version           : WINDOWS:1.0,1.5,1.51,1.52; winnt:2.0,2.1,2.2,4.0,4.1,4.2,5.0,6.0
Platform          : WINDOWS winnt 
Issue type        : kbbug 

Last Reviewed: May 17, 1999