MCU死循环,国外工程师为什么喜欢for(;;) ?
来源:开源Linux 发布时间:2024-06-21
分享至微信
![](/_nuxt/img/wechaticon.317e48d.png)
首先,问大家一个问题:你们写单片机程序【死循环】时,喜欢用用 for(;;) 还是while(1)?
一位工程师发现,国外工程师在给demo在做死循环时用的是for(;;),而不是常用的while(1)。这仅仅是个人习惯的问题,还是有更深层次的含义?
没啥区别党:都是心理作用
#include<stdio.h>
int main()
{
for(;;)
{
printf("for\n");
}
}
![](https://img.icspec.com/article/d77e52aa2f7811ef85bf00163e1eb85a.png)
#include<stdio.h>
int main()
{
while(1)
{
printf("while\n");
}
}
![](https://img.icspec.com/article/d7821e082f7811ef8fe700163e1eb85a.png)
正方观点:哪有好的编译器
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句语
![](https://img.icspec.com/article/d77914162f7811ef92a200163e1eb85a.png)
工程师实地测试:和编译器和优化有关
工程师实地测试:和编译器和优化有关
![](https://img.icspec.com/article/d7b0c7b22f7811ef85bf00163e1eb85a.png)
![](https://img.icspec.com/article/d7ae12f62f7811ef92a200163e1eb85a.png)
![](https://img.icspec.com/article/d7ba59bc2f7811ef92a200163e1eb85a.png)
![](https://img.icspec.com/article/d7dccca42f7811ef85bf00163e1eb85a.png)
参考文献
[ 新闻来源:开源Linux,更多精彩资讯请下载icspec App。如对本稿件有异议,请联系微信客服specltkj]
存入云盘 收藏
举报
全部评论
暂无评论哦,快来评论一下吧!
![](https://img.icspec.com/common/images/artbrand.png)
![](https://img.icspec.com/xxt/avatar/3984e5a6fe4a49fc8c6bd35e393d9ce1.jpg)
开源Linux
专业的Linux技术社区和Linux操作系统学习平台,专注分享Linux运维、Linux系统开发、网络编程、云计算等专业领域知识。
查看更多
相关文章
阻碍AGI 研究,谷歌工程师指责OpenAI!
2024-06-13
日本将派遣上百名工程师赴美培训
2024-06-17
TI:印度拥有丰富的工程师人才库
一周前
年薪高达80万!鸿蒙工程师被抢疯
6 天前
嵌入式工程师掌握编程的几个要素
2024-05-11
热门搜索