&是什么QUOT;比较布尔前pression不变的是永远真QUOT;警告是什么意思? [英] What does "Comparing constant with boolean expression is always true" warning mean?
问题描述
这是什么意思的警告( I
和Ĵ
不是常量):
我一直在试图谷歌这一点,但它并没有给我任何结果。
警告:与布尔前pression恒10比较
总是如此[-Wtautological恒定输出范围的,比较]结果如果((0℃; = I&下; = 10)及及(0℃; = J&下; = 10)){
块引用>在我的程序,
I
和Ĵ
不是恒定值,他们做的改变。解决方案在
C
,链接关系运算符这样的都不是有效的设计。因此,(0℃= I< = 10)
是不是做你认为它应该做的。它是越来越评为
((0℃= I)LT; = 10)
这基本上是任
0℃; = 10
,生产1
(认为是TRUE值)1 LT; = 10
,也产生1
(认为是TRUE值)可悲的是,这两者都是出路比预期路径。
解决方案:您需要打破你的condtion支票像
(0℃; = I)及和放大器; (ⅰ&下; = 10)
What does this warning mean (
i
andj
are not constants):I have been trying to Google this but it does not give me any results.
warning: comparison of constant 10 with boolean expression is always true [-Wtautological-constant-out-of-range-compare]
if ((0<=i<=10)&&(0<=j<=10)){
In my program,
i
andj
are not constant values and they do change.解决方案In
C
, chaining of relational operators like this are not valid design. Thus,(0<=i<=10)
is not doing what you think it should be doing. it is getting evaluated as
((0<=i) <= 10 )
which is basically either
0 < = 10
, producing1
(considered TRUE value)1 < = 10
, also producing1
(considered TRUE value)sadly, both of which are way out than the expected path.
Solution: you need to break down your condtion check like
(0 <= i) && ( i<=10)
这篇关于&是什么QUOT;比较布尔前pression不变的是永远真QUOT;警告是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!