MCU做死循环时,到底应该用for(;;) 还是wihile(1)
没啥区别党:都是心理作用
#include<stdio.h>
int main()
{
for(;;)
{
printf("for\n");
}
}
int main()
{
while(1)
{
printf("while\n");
}
}
正方观点:哪有好的编译器
label:
……
mov a, #1
jnz label
反方观点:这种代码过时了
GJB 8114-2013 R-1-9-4:无限循环必须使用while(1)语句,禁止使用for(;;)等其他形式
CppCoreGuidelines ES.73:Prefer a while-statement to a for-statement when there is no obvious loop variable
360 safe rules: for语句没有明确的循环变量时应改用while句语
工程师实地测试:和编译器和优化有关
参考文献
微信扫码关注该文公众号作者
戳这里提交新闻线索和高质量文章给我们。
来源: qq
点击查看作者最近其他文章