Matthew Smith
February 23rd, 2000, 11:12 PM
Hi, I believe that my colleagues and I have discovered a bug in the Visual C++ 6.0 compiler. We're using Visual C++ 6.0 sp3 on NT 4.0 sp6a. The following C++ code will compile and give the correct results (11) if compiled in debug or /O (optimize for space) mode. If compiled for speed, with /02, it gives incorrect results (2). Here is the code:
#include <iostream.h>
double tol=-1.0;
int main(void) {
double grid[11];
int ci=0;
grid[ci] = 0.0;
while (grid[ci]<10.0) {
double step_to_end = 10.0 - grid[ci];
if (tol>0.0) cerr << "should not be here" << endl;
if ( 1.0>(step_to_end-0.0) ) {
// cerr << "really shouldn't be here" << endl;
ci++;
grid[ci] = grid[ci-1] + step_to_end;
} else {
#if 0
grid[ci+1] = grid[ci] + 1.0;
ci++;
#else
ci++;
grid[ci] = grid[ci-1] + 1.0;
#endif
}
}
cout << endl << "num points: " << ci+1 << endl;
return ci+1;
}
Is this a known bug? Do patches exist? It's a little scary that something this simple produces incorrect compiled code. Any input is greatly appreciated.
-Matt Smith
#include <iostream.h>
double tol=-1.0;
int main(void) {
double grid[11];
int ci=0;
grid[ci] = 0.0;
while (grid[ci]<10.0) {
double step_to_end = 10.0 - grid[ci];
if (tol>0.0) cerr << "should not be here" << endl;
if ( 1.0>(step_to_end-0.0) ) {
// cerr << "really shouldn't be here" << endl;
ci++;
grid[ci] = grid[ci-1] + step_to_end;
} else {
#if 0
grid[ci+1] = grid[ci] + 1.0;
ci++;
#else
ci++;
grid[ci] = grid[ci-1] + 1.0;
#endif
}
}
cout << endl << "num points: " << ci+1 << endl;
return ci+1;
}
Is this a known bug? Do patches exist? It's a little scary that something this simple produces incorrect compiled code. Any input is greatly appreciated.
-Matt Smith