&是什么QUOT;比较布尔前pression不变的是永远真QUOT;警告是什么意思? [英] What does "Comparing constant with boolean expression is always true" warning mean?

查看:1060
本文介绍了&是什么QUOT;比较布尔前pression不变的是永远真QUOT;警告是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么意思的警告( 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 and j 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 and j 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, producing 1 (considered TRUE value)
  • 1 < = 10, also producing 1 (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屋!

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