使用/ Og时C代码中的无限循环 [英] Endless Loop in C-Code when Using /Og

查看:47
本文介绍了使用/ Og时C代码中的无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Visual Studio .NET 2003.当使用该编译器时,

以下示例代码在while中进入无限循环。当使用

/ Og优化选项时循环:


#include< stdlib.h>

int resize(int * incsize,int min_size){

while(* incsize< = min_size){

* incsize =(int)(* incsize * 1.25);

}

if(min_size> 60)返回0;

否则返回min_size;

}

int main(){

int incsize = 10;

返回调整大小(& incsize,12);

}


在while循环中使用指针和实数值进行

乘法时会出现问题。在循环之后它还需要一些额外的代码

(除了返回或打印语句之外)。


对我来说,这看起来像编译器错误。我在微软网站上查看了Visual Studio .NET 2003的

补丁,但我没有看到任何补丁。有没有人知道

这个问题的补丁如果是的话,我可以从哪里下载呢?


谢谢,

解决方案

嗨Bev,


这里没有解决方案,但这里只是一个奇怪的问题。为什么while

循环呢?如果没有它,代码会做同样的事情,

因为它只返回基于未更改的输入参数min_size(

incsize对输出没有影响可能挂起在

循环中)。事实上,如果min_size是大于60的
,那么resize()所做的所有方法都返回''0',否则min_size本身就是...


我猜这是对你实际代码的简化,在这种情况下我知道你只是把它简化为一个更简单的东西显示

问题。但那么为什么if(m_size> 60)......代码那里,因为它b / b $ b $不是问题的一部分?在你的示例代码中,对它的调用应该是

返回12,因为12小于或等于60 ...


[== P == ]


" Bev in TX" < bev in TX@discussions.microsoft.com >在消息中写道

新闻:7A ********************************** @ microsof t.com ...

我们正在使用Visual Studio .NET 2003.当使用该编译器时,以下示例代码在while中进入无限循环。当使用
/ Og优化选项时循环:

< stdlib.h>
int resize(int * incsize,int min_size){
while(* incsize< = min_size){
* incsize =(int)(* incsize * 1.25);
}
if(min_size> 60)返回0;
返回min_size;
}
int main(){
int incsize = 10;
返回resize(& incsize,12);
}

在while循环中使用指针和实数值进行乘法时会出现问题。在循环之后它还需要一些额外的代码(除了返回或打印语句之外)。

对我来说,这看起来像编译器错误。我在Microsoft网站上查看了Visual Studio .NET 2003的补丁,但我没有看到任何补丁。有没有人知道这个问题的补丁?如果是的话,我可以从哪里下载它?

谢谢,



这是一个示例程序 - 而不是真实的程序。我减掉了一切不会影响臭虫的



Bev in TX


I还应该说真正的代码在循环后重新分配内存

- 我只是试图删除所有复杂但仍然产生错误的b $ b。

We are using Visual Studio .NET 2003. When using that compiler, the
following example code goes into an endless loop in the "while" loop when the
/Og optimization option is used:

#include <stdlib.h>
int resize(int *incsize, int min_size) {
while(*incsize <= min_size) {
*incsize = (int)(*incsize * 1.25);
}
if ( min_size > 60 ) return 0;
else return min_size;
}
int main() {
int incsize = 10;
return resize(&incsize, 12);
}

The problem occurs when using a pointer and real value for the
multiplication in the while loop. It also requires some additional code
(other than just a return or print statement) after the loop.

To me, this looks like a compiler bug. I looked on Microsoft web site for
patches to Visual Studio .NET 2003 but I did not see any. Does anyone know
of a patch for this issue and if so, from where can I down load it?

Thanks,

解决方案

Hi Bev,

No solution for you here, but just a weird question here. Why is the while
loop there at all? The code would do exactly the same thing without it,
since it returns based only on the unchanged inputed parameter min_size (
incsize has no affect on the output exact possibly to hang in the while
loop). In fact, all the method resize() does is return ''0'' if min_size is
greater than 60, and min_size itself otherwise...

I''m guessing this is a simplification of your actual code, in which case I
understand that you''re just boiling it down to a simpler thing that displays
the problem. But then why is the "if (m_size >60)..." code there, since it
is not part of the problem? In your example code the call to it should
return a 12 since 12 is less than or equal to 60...

[==P==]

"Bev in TX" <Bev in TX@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...

We are using Visual Studio .NET 2003. When using that compiler, the
following example code goes into an endless loop in the "while" loop when
the
/Og optimization option is used:

#include <stdlib.h>
int resize(int *incsize, int min_size) {
while(*incsize <= min_size) {
*incsize = (int)(*incsize * 1.25);
}
if ( min_size > 60 ) return 0;
else return min_size;
}
int main() {
int incsize = 10;
return resize(&incsize, 12);
}

The problem occurs when using a pointer and real value for the
multiplication in the while loop. It also requires some additional code
(other than just a return or print statement) after the loop.

To me, this looks like a compiler bug. I looked on Microsoft web site for
patches to Visual Studio .NET 2003 but I did not see any. Does anyone
know
of a patch for this issue and if so, from where can I down load it?

Thanks,



That is an example program -- not the real thing. I pared out everything
that did not affect the bug.

Bev in TX


I should also have said that the real code reallocates memory after the loop
-- I just tried to remove everything that was complicated but still produce
the error.


这篇关于使用/ Og时C代码中的无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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