[关闭]
@Purpose 2017-04-04T08:27:21.000000Z 字数 3537 阅读 1766

华为编程规范

学习笔记


排版

  1. if(code){
  2. if(code){
  3. /*code*/
  4. }
  5. }
  1. int Date;
  2. int Time;
  3. if(code){
  4. /*code*/
  5. }
  6. for(code){
  7. /*code*/
  8. }
  1. /*Wrong*/
  2. rect.length= 0; rect.width = 0;
  3. /*Right*/
  4. rect.length= 0;
  5. rect.width =0;
  1. /*Wrong*/
  2. if (pUserCR== NULL) return;
  3. /*Right*/
  4. if (pUserCR== NULL){
  5. return;
  6. }

注释

  1. /******************************
  2. Copyright: 1988-1999, Huawei Tech. Co., Ltd.
  3. File name: 文件名
  4. Description: 用于详细说明此程序文件完成的主要功能,与其他模块或函数的接口,输出值、取值范围、含义及参数间的控制、顺序、独立或依赖等关系
  5. Author: 作者
  6. Version: 版本
  7. Date: 完成日期
  8. History: 修改历史记录列表,每条修改记录应包括修改日期、修改者及修改内容简述。
  9. *************************************/
  1. /*************************************************
  2. Function: // 函数名称
  3. Description: // 函数功能、性能等的描述
  4. Calls: // 被本函数调用的函数清单
  5. Called By: // 调用本函数的函数清单
  6. Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
  7. Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
  8. Input: // 输入参数说明,包括每个参数的作用、取值说明及参数间关系。
  9. Output: // 对输出参数的说明。
  10. Return: // 函数返回值的说明
  11. Others: // 其它说明
  12. *************************************************/
  1. /* getreplicate sub system index and net indicator */
  2. repssn_ind = ssn_data[index].repssn_index;
  3. repssn_ni = ssn_data[index].ni;
  1. /* activestatistic task number */
  2. #define MAX_ACT_TASK_NUMBER 1000
  3. #define MAX_ACT_TASK_NUMBER 1000 /* active statistic task number */
  1. /* sccpinterface with sccp user primitive message name */
  2. enumSCCP_USER_PRIMITIVE
  3. {
  4. N_UNITDATA_IND, /* sccp notify sccp user unit data come*/
  5. N_NOTICE_IND, /* sccp notify user the No.7 network cannot */
  6. /* transmission this message */
  7. N_UNITDATA_REQ, /* sccp user's unit data transmissionrequest*/
  8. };
  1. /* TheErrorCode when SCCP translate */
  2. /* GlobalTitle failure, as follows */ // 变量作用、含义
  3. /* 0 - SUCCESS 1 - GT Table error */
  4. /* 2 - GT error Others - no use */ // 变量取值范围
  5. /* onlyfunction SCCPTranslate() in */
  6. /* thismodual can modify it, and other */
  7. /* modulecan visit it through call */
  8. /* thefunction GetGTTransErrorCode() */ // 使用方法
  9. BYTEg_GTTranErrorCode;
  1. if (...){
  2. // programcode
  3. while (index< MAX_INDEX){
  4. // programcode
  5. } /* end ofwhile (index < MAX_INDEX) */ // 指明该条while 语句结束
  6. } /* end ofif (...)*/ // 指明是哪条if 语句结束

命名规范


可读性

  1. /*Wrong*/
  2. high<< 8 | low
  3. a | b&& a & c
  4. a | b < c& d
  5. /*Right*/
  6. (high << 8) | low
  7. (a | b) && (a & c)
  8. (a | b) < (c & d)

涉及物理状态或者含有物理意义的常量,不应直接使用数字,必须用有意义的枚举或宏来代替。

  1. #defineTRUNK_IDLE 0
  2. #defineTRUNK_BUSY 1
  3. if(Trunk[index].trunk_state == TRUNK_IDLE){
  4. Trunk[index].trunk_state= TRUNK_BUSY;
  5. //program code
  6. }
  1. /*Wrong*/
  2. rect.length = 10;
  3. char_poi = str;
  4. rect.width = 5;
  5. /*Right*/
  6. rect.length = 10;
  7. rect.width = 5; // 矩形的长与宽关系较密切,放在一起。
  8. char_poi = str;
  1. /*Wrong*/
  2. #defineRECTANGLE_AREA( a, b ) (a) * (b)
  3. /*Right*/
  4. #defineRECTANGLE_AREA( a, b ) ((a) * (b))
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注