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/