当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
高精度焊接机械臂定位
Link to some good tutorials or notes about network security and record them
几种智能机器人室内定位方法对比
Flatten arrays
Introduction to sap query enhanced development
Upload labs range practice
Implementation of new
Intranet security attack and defense: a practical guide to penetration testing (6): domain controller security
php高精度计算
利用sqlmap注入获取网址管理员账号密码
Go语学习笔记 - 数组 | 从零开始Go语言
1216_MISRA_C规范学习笔记_控制流的规则要求
[problem solving] vs2019 solves the problem that the EXE file generated by compilation cannot be opened
Anti shake and throttling
云计算赛项--2020年赛题基础部分[任务3]
Ribbon启动流程
【无标题】
Quick rehearsal exercise
Implementation of promise all
Ubuntu安装Mysql并查询平均成绩







