BrianShields wrote:
I only ever saw the compiler bug you linked once and it was in a pretty munged loop (nested STL adaptors, Managed code), I'm surprised something so simple could reproduce it.
Actually, the SSCCE for the loop optimization bug was pretty short itself:
// Using VS .NET 2003, when compiling without /O2, output is:
// before: abcd after: cdxx
// but compiling with /O2, output is:
// before: abcd after: cxxx
//
// This seems to be fixed with VS .NET 2003 SP1
#include <iostream>
int main()
{
char c[4];
c[0] = 'a';
c[1] = 'b';
c[2] = 'c';
c[3] = 'd';
std::cout << "before: " << c\[0\] << c\[1\] << c\[2\] << c\[3\] << " ";
for (int n = 2; n > 0; --n) {
for (int i = 0; i < 3; i++) {
c\[i\] = c\[i+1\];
}
c\[3\] = 'x';
}
std::cout << "after: " << c\[0\] << c\[1\] << c\[2\] << c\[3\] << std::endl;
return 0;
}
BrianShields wrote:
Have you utterly verified that index 0 in that case was true in Release as well?
Yes, if I comment out the original loop and display the contents of the array in a MessageBox, indeed the first element is true. It was retrieving the same data from the DB as in Debug mode anyway.
-- Marcus Kwok