MSVC ++ 6.0编译器优化错误? [英] MSVC++ 6.0 Complier optimization bug??

查看:159
本文介绍了MSVC ++ 6.0编译器优化错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将以下代码编写到Visual C ++ 6中的控制台程序中。如果你建立一个发布版本并选择自定义优化并选择

''一般优化'作为唯一的优化,那么你最终会得到

结果不正确。每一行似乎都很重要,甚至是无关的b $ b b。任何人都有时间或者有兴趣试试这个吗?b $ b为自己尝试解释一下吗?


#include" stdafx.h"

#include< string>


int main(int argc,char * argv [])

{

std :: string s1; < - 这很重要


for(int i = 0; i< 4; i ++)

{

int shift = i * 4; < - 这很重要

short temp = shift; < - 这很重要

printf(" Generated%d \ n",temp);

}


返回0;

而(1)< - 这很重要,把它取出来问题

消失

{

}

}


此程序使用指定的优化运行的结果如下:
: />
生成0

生成0

生成0

生成0


注意:这是(非常)精简版的某些生产代码我已经写了因为这个奇怪的错误而写的失败了。现在我打算只删除优化,直到可以确定正确的修复。我希望

某人有一些见解。

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.

推荐答案

当然我的意思是编译器...... br />

编译器的帖子应该进入alt.tools ...无论如何,帖子是

严重;)

Of course I meant COMPILER....

complier postings should go into alt.tools...anyway, the posting is
serious ;)




jryden写道:

jryden wrote:
当然我的意思是编译器....

编译器的贴子应该进入alt。工具...无论如何,帖子是严肃的;)
Of course I meant COMPILER....

complier postings should go into alt.tools...anyway, the posting is
serious ;)




我不能在7.1中重现这个问题



I can''t recreate the issue in 7.1


我使用vc6sp5编译了以下代码,无法重现

错误。


cl -GX -Og test.cpp


#include< cstdio>

#include< string>


int main( int argc,char * argv [])

{

std :: string s1; //< - 这很重要


for(int i = 0; i< 4; i ++)

{

int shift = i * 4; //< - 这很重要

short temp = shift; //< - 这很重要

printf(" Generated%d \ n",temp);

}


返回0;


而(1)//< - 这很重要,把它取出来问题

消失

$

}
I compiled the following code using vc6sp5 and could not reproduce
the error.

cl -GX -Og test.cpp

#include <cstdio>
#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
{
}
}


这篇关于MSVC ++ 6.0编译器优化错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆