当前位置:网站首页>1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
2022-04-23 08:07:00 【grey_ csdn】
All learning summary : https://github.com/GreyZhang/misra_c_hacking
There can be no code that cannot be executed , Except for defensive codes . About what defensive code is , In the following rules, you can continue to understand . For the various projects I'm dealing with now , In fact, the biggest conflict in this part may be that the calibration selection enables the branch to take effect . This part can indeed be detected at the compilation stage , However, in practical application, it should be retained .
All non empty expressions can either produce some effective effect , Either it can affect the selection or change of program flow . Simple invalid handling is not allowed .
An empty statement must be followed by at least one space , Then you can add notes . in addition , You cannot use empty statements after comments .
These requirements are not explained directly , Because it's direct enough . First , Can't use goto; secondly , Can't use continue; also , Each cycle can only have at most one break For the end of the loop . So far , The projects I came into contact with may not completely deal with such requirements . Some protocol stacks in legacy code seem to have goto, And I used it myself when designing software continue. in addition , I seem to have seen many break The situation of . Actually , If you comply with these requirements, there is also a way to solve , Adding some state variables and conditional branches can easily solve .
A function can only have an exit point at the end of the function . Actually , I've seen open source before 1939 The agreement seems to have done a good job in this regard .
Various cycles and conditional structures , It is basically right to use curly braces as much as possible .
The best time to meet this rule should be combined with what is written above , Try to handle conditional branches with curly braces . in addition , every last if Should be one else end . And this else It's the defensive programming mentioned earlier , If it really can't be implemented , Then write a note here to explain the reason . This one was mentioned by others in my work many years ago, and it was printed in my own memory , I didn't write much code at that time , But today, these requirements have solidified into my own coding habits .
版权声明
本文为[grey_ csdn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230645316190.html
边栏推荐
- 3C装配中的机械臂运动规划
- Go语学习笔记 - 结构体 | 从零开始Go语言
- Intranet penetration series: dns2tcp of Intranet tunnel
- 学fpga(从verilog到hls)
- Intranet penetration series: icmptunnel of Intranet tunnel (Master James Barlow's)
- Convert object to URL
- Intranet penetration series: ICMP of Intranet tunnel_ Tran
- Implementation of promise all
- Redis -- why is the string length of string emstr the upper limit of 44 bytes?
- Ribbon start process
猜你喜欢
随机推荐
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
Mysql database backup and recovery under Linux (full + incremental)
Reading notes
Redis transaction implements optimistic locking principle
在MATLAB中快速画圆(给出圆心坐标和半径就能直接画的那种)
利用sqlmap注入获取网址管理员账号密码
Essays (updated from time to time)
Redis--为什么字符串emstr的字符串长度是44字节上限?
Concours de compétences en informatique en nuage - - première partie de l'environnement cloud privé openstack
Face to face summary 2
BUFFCTF文件中的秘密1
国基北盛-openstack-容器云-环境搭建
feign如何集成hystrix
【无标题】
Internal network security attack and defense: a practical guide to penetration testing (5): analysis and defense of horizontal movement in the domain
Depth of binary tree
GUI,CLI与Unix哲学
【编程实践/嵌入式比赛】嵌入式比赛学习记录(二):基于TCP的图片流传输
upload-labs 靶场练习
Fibula dynamic programming