The coding specification can be discussed in four ways:1 spaces and Blank lines
Space is the art of landscape, and blank line is the art of vertical.
- The keyword if,while,for and the following parentheses add spaces, such as while (1), and parentheses do not add spaces to the expression in parentheses.
- The binocular operator is added with a space on both sides, and the monocular operator does not. For example: i = i+1; ++i;
- Some end widths are displayed in 80 columns, so for compatibility, the general number of columns exceeds 80 columns, and the line breaks.
- Instead of using tab indentation, tab is replaced with two spaces.
- Between functions, global variables, header file references, and other logical paragraphs, add blank lines.
- The Swith is aligned with the statement block amount case default.
- Brackets {}, separate rows.
- function inside if the code is longer, it should be grouped and blank line.
2 Notes
Single-line comment with//, multiline comment with
- The entire source file at the top of the comment, filename, author, history.
- function comments, function functions, parameters, return values, error codes, written on top of the function, do not leave blank lines.
- A comment for the statement group.
- Single-line annotation on the right.
- A complex structure, a macro-defined comment.
3 identifier naming
- Name to be clear, with complete words or abbreviations.
- Variable functions and types are named with all lowercase underlines. Constants are named with all caps and underscores.
- Global variables, and the naming of global functions must be detailed.
4 Functions
- Functions should be as simple as possible, simpler and easier to maintain.
- A function only does one thing.
- The internal indentation of the function should not be too much, not more than 4 layers.
- More than 10 local variables of the function should also be considered for partitioning.
- The function does not write too long, more than 50 lines, consider to divide.
- Function names should include verbs, and general functions are to identify an action. Get_name,insert_row.
C Language Coding Specification