C Language Coding Specification

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.