gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:24:56 26 4
gpt4 key购买 nike

当我为 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com