Programming specification Learning (1): annotation and naming

Source: Internet
Author: User

Now that you are ready to learn the programming specifications, let's take a look at Huawei's specifications first. Starting from simple file comments and naming, these two pieces are the easiest to confuse, I still have to stick to it. I can watch it every day. I don't believe it's fixed every time I look at programming. Some of the following normative content has been modified.

Annotation specification: file Annotation

/*************************************** **************************

Copyright:

File Name: File Name

Description: used to describe the main functions completed by this program file.

Author: Author

Version: Version

Date: Completion Date

History: A list of modified history records. Each modification record should include the modification date, modifier, and brief description of the modification content.

**************************************** *************************/

Function notes:

/*************************************** **********

Function: // function name

Description: // description of function functions and performance

Called by: // list of functions that call this function

Input: // description of input parameters, including the operation of each parameter

// Use, value description, and relationship between parameters.

Output: // description of the output parameters.

Return: // description of the function return value

Others: // other instructions

**************************************** *********/

For short comments, "\" is used. For comments with more than three rows, "/**/" is used for comments. The comments must be written above or next to the commented content.

The macro definition and data structure declaration should be clearly described, and each item of the structure content should be clearly described in the data structure.

For global variables, it is best to assign values and modify values in a function, and make a note: The Role of the variable, the value range, and which functions are used

 

File naming: Although there are many methods, there are too many methods that I don't know which one to use, so it's all confusing to use them. You should choose the right one to define yourself, so that you are not afraid of confusion.

Function Name: the method in which the first letter is capitalized, for example, writedate ();

Macro definition and Data Type: in uppercase, for example, # define max 10

Variable name: The name is underlined in lower case. The global variable is preceded by G _ (global), and the static variable in the function uses S _ (static ), the global variables in the file are named by L _ (local), the constant is named by C _ (const), and the data type can be u8, u32, S8, S16, s32 and so on. For example, a u8 global variable can be expressed as gu8 _. It seems a bit strange. This is another consideration.

 

Let's look at the rest. Stick to this part first, and it will be about the same.

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.