gpt4 book ai didi

c - PC Lint while(TRUE) 与 for(;;)

转载 作者:太空狗 更新时间:2023-10-29 14:57:59 25 4
gpt4 key购买 nike

我是第一次使用 PC Lint。当 PC Lint 警告我关于我的 while(TRUE) 时,我正在“检查”我的代码。

是这样写的:

716: while(1) ... -- A construct of the form while(1) ... was found.

Whereas this represents a constant in a context expecting a Boolean, it may reflect a programming policy whereby infinite loops are prefixed with this construct. Hence it is given a separate number and has been placed in the informational category. The more conventional form of infinite loop prefix is for(;;).

我没看懂这句话。谁能帮助我理解它?

最佳答案

文中说尽管 while(TRUE)(它被预处理为 while(1))是一个完全有效的无限循环,但更传统的编写形式无限循环是

for(;;)
{
...
}

因为它根本不使用任何值,因此不容易出错。

关于c - PC Lint while(TRUE) 与 for(;;),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7528263/

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