c - Lint 警告 506 : prio3: Constant value Boolean

标签 c warnings lint

当我为 lint 运行我的代码时,我收到警告说“警告 506:常量 bool 值”对于我使用宏分配变量的行。

    #define FALSE   (0) 
    #define TRUE    (!FALSE)
    typedef char              BOOL;
    BOOL fTriggerCallback;

    fun_1()
    {
        fTriggerCallback = FALSE; //No warning
    }

    fun_2()
    {
       if(fTriggerCallback == FALSE)
         {
             fTriggerCallback =TRUE; //here is the warning
         }
    }

    fun_3()
    {
        fTriggerCallback =TRUE; //here is the warning
    }

在此代码中,我在将 TRUE 分配给变量时收到警告。在我将 FALSE 分配给变量的地方看不到警告。

但是当我更改宏 #define TRUE 1 时,警告已修复。我不知道这背后的确切原因。

最佳答案

Lint 正在提示,因为 TRUE 被扩展为 (!FALSE),而 (!FALSE) 被扩展为 (!0)。错误 506 标志:

A Boolean, i.e., a quantity found in a context that requires a Boolean such as an argument to && or || or an if() or while() clause or !, was found to be a constant and hence will evaluate the same way each time.

Lint 提示对常量值 (0) 的逻辑操作 (!)。 如果C99's stdbool.h不可用,读入PC-lint's strong types .

关于c - Lint 警告 506 : prio3: Constant value Boolean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41953303/

相关文章:

c - 这两个库和处理器指令有什么区别?

c - 完整桌面的 WinAPI 鼠标移动通知

c - 汇编返回 int 到 C 函数段错误

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

mysql - 如何在MySQL存储过程中抛出警告?

c - 获取格式化字符串到变量

multithreading - {DCC 警告} W1036 变量 '$frame' 可能尚未初始化?

javascript - 如何在 Vim 中使用 JSLint

想要 RTF 短绒

go - VSCode 中更严格的 Golang lint