C Coding Standard - C 编程规范

C Coding Standard - C 编程规范

C Coding Standard
https://users.ece.cmu.edu/~eno/coding/CCodingStandard.html

Adapted from C++ Coding Standard and NetBSD’s style guidelines
http://www.possibility.com/Cpp/CppCodingStandard.html

C++ Coding Standard
https://users.ece.cmu.edu/~eno/coding/CppCodingStandard.html

1. Contents

1. Names
(important recommendations below)
Include Units in Names
Structure Names
C File Extensions
(other suggestions below)
Make Names Fit
Variable Names on the Stack
Pointer Variables
Global Constants
Enum Names
#define and Macro Names
2. Formatting
(important recommendations below)
Brace {} Policy
Parens () with Key Words and Functions Policy
A Line Should Not Exceed 78 Characters
If Then Else Formatting
switch Formatting
Use of goto,continue,break and ?:
(other suggestions below)
One Statement Per Line
3. Documentation
(important recommendations below)
Comments Should Tell a Story
Document Decisions
Use Headers
Make Gotchas Explicit
Commenting function declarations
(other suggestions below)
Include Statement Documentation
4. Complexity Management
Layering
5. Miscellaneous
(important recommendations below)
Use Header File Guards
Mixing C and C++
(other suggestions below)
Initialize all Variables
Be Const Correct
Short Functions
No Magic Numbers
Error Return Check Policy
To Use Enums or Not to Use Enums
Macros
Do Not Default If Test to Non-Zero
Usually Avoid Embedded Assignments
Commenting Out Large Code Blocks
Use #if Not #ifdef
Miscellaneous
No Data Definitions in Header Files

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值