什么是&QUOT的解释;警告:假定循环不是无限" [英] What is the explanation for "warning: assuming that the loop is not infinite"

查看:156
本文介绍了什么是&QUOT的解释;警告:假定循环不是无限"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚采取改变许多变量决定从无符号 INT 并呼吁重新编译code有问题,被迎面而来此警告消息:

I had just taken the decision to change as many variables from unsigned to int and upon recompiling the code in question, was greeted by this warning message:

freespace_state.c:203: warning: assuming that the loop is not infinite

在这行:

for (x = startx; x <= endx; ++x, ++xptr)

这循环是code(含空格/支架等)的60线,并有一个转到在其中,并且至少出现继续

This loop is 60 lines of code (inc white space/brackets etc), and has a goto within it, and at least one occurrence of continue.

在这种情况下,我认为我是美联社preciative的GCC是假设这个循环不是无限的,因为,它应该永远不会无限循环。

In this case, I think I am appreciative that GCC is assuming this loop is not infinite, because, it should never loop indefinitely.

什么是GCC想在这里告诉我?

What is GCC trying to tell me here?

警告的语法几乎是暗示性的警告应其他一些警告的范围内采取,但也有上下文中没有。


这一切都完全我自己的错。我偷了一些优化,并警告选项从一个问题就在这里的某个地方没有真正理解他们,从那以后忘记了他们。

[edit] It's all completely my own fault. I stole some optimization and warning options from a question on here somewhere without really understanding them, and had since forgotten about them.

请参阅马克Rushakoff的回答,另外,我也用 -Wunsafe - 环 - 优化,如果GCC正在对一个循环的假设明确警告。见<一href=\"http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html\">http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

See Mark Rushakoff's answer, and in addition, I have also used -Wunsafe-loop-optimizations to explicitly warn if GCC is making assumptions about a loop. See http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

推荐答案

根据这从2005年 GCC补丁,看来GCC正在执行不安全循环优化(你被警告,因为 -funsafe - 环 - 优化设置) 。如果循环的无限的,这种特殊的优化会以某种方式失败。

According to this GCC patch from 2005, it appears that GCC is performing an "unsafe loop optimization" (and you are being warned because -funsafe-loop-optimizations is set). If the loop is infinite, this particular optimization will fail somehow.

既然你说这是一个循环终止,这听起来好像你没有什么可担心的。

Since you said it is a terminating loop, it sounds as though you have nothing to worry about.

补丁另一个相关的部分:

Another relevant part of the patch:


@opindex Wunsafe-loop-optimizations
Warn if the loop cannot be optimized because the compiler could not
assume anything on the bounds of the loop indices.  With
@option{-funsafe-loop-optimizations} warn if the compiler made
+such assumptions.

这篇关于什么是&QUOT的解释;警告:假定循环不是无限&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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