如何清除C中的此棉绒警告? [英] how to clean this lint warning in c?

查看:88
本文介绍了如何清除C中的此棉绒警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

#define NUMBER_OF_ROOMS

if((unsigned int)(NUMBER_OF_ROOMS - 2) > 20)
{
   // do something here
}

但是我得到了一个不起毛的警告:Warning 506: Constant value Boolean,这是什么意思,以及如何解决?

but I got a lint warning:Warning 506: Constant value Boolean, what does this mean and how to fix it?

推荐答案

这意味着表达式的值是常量,因此if是毫无意义的,因为在编译时知道它是否为真是否.

It means that the value of the expression is constant, and thus the if is pointless since it's known at compile-time whether or not it will be true or not.

您当然可以使其更具动态性,或者改用预处理器:

You could of course make it more dynamic, or use the preprocessor instead:

#if (NUMBER_OF_ROOMS - 2) > 20
// do something here
#endif

我认为强制转换为(unsigned int)是没有意义的,如果这些值确实接近整数精度的边界,那么Jens Gustedt的评论就适用.

I assumed the cast to (unsigned int) was pointless, if these really were values close to the boundaries of the integer precision, then Jens Gustedt's comment applies.

这篇关于如何清除C中的此棉绒警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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