J
jryden
I wrote the following code into a console program in Visual C++6. If
you build a release build and select custom optimizations and select
'general optimizations' as the only optimization then you will end up
with incorrect results. Every line seems to be important, even the
unrelated bits. Any one have the time or inclination to try this out
for themselves and try to explain it?
#include "stdafx.h"
#include <string>
int main(int argc, char* argv[])
{
std::string s1; <- This is important
for(int i = 0; i<4; i++)
{
int shift = i*4; <- This is important
short temp = shift; <- This is important
printf("Generated %d\n", temp);
}
return 0;
while(1) <- This is important, take it out and the problem
disappears
{
}
}
The result of this program run with the specified optimizations is as
follows:
Generated 0
Generated 0
Generated 0
Generated 0
Note: This is (very) stripped down version of some production code I
had written that failed due to this odd bug. For now I plan to just
remove the optimizations until a proper fix can be determined. I hope
someone has some insight.
you build a release build and select custom optimizations and select
'general optimizations' as the only optimization then you will end up
with incorrect results. Every line seems to be important, even the
unrelated bits. Any one have the time or inclination to try this out
for themselves and try to explain it?
#include "stdafx.h"
#include <string>
int main(int argc, char* argv[])
{
std::string s1; <- This is important
for(int i = 0; i<4; i++)
{
int shift = i*4; <- This is important
short temp = shift; <- This is important
printf("Generated %d\n", temp);
}
return 0;
while(1) <- This is important, take it out and the problem
disappears
{
}
}
The result of this program run with the specified optimizations is as
follows:
Generated 0
Generated 0
Generated 0
Generated 0
Note: This is (very) stripped down version of some production code I
had written that failed due to this odd bug. For now I plan to just
remove the optimizations until a proper fix can be determined. I hope
someone has some insight.