C--变量的命名规则

Posted on 2016-08-21 19:36  WhatTD  阅读(681)  评论(0)    收藏  举报

规则1、标识符最好采用英文单词或其组合,不允许使用拼音。

规则3、当标识符由多个词组成时,每个词的第1个字母大写,其余全部小写:

          int   CurrentVal;

规则5、对在多个文件之间共同使用的全局变量或函数  要加范围限定符 (建议使用模块名(缩小) 作为范围限定符),比如 GUI_ 等。

 

标识符的命名规则 

作用域前缀命名规则:标识符类型 --- 作用域前缀

                            Global Variable              g

                  File Static Variable(native)     n

                Function Static Variable             f

                     Auto Variable                         a

                  Global  Function                        g

                  Static   Function                        n

 

数据类型前缀命名规则:   前缀 + 数据类型  +  示例

                           bt                bit                Bit   btVariable;

                            b              boolean          boolean   bVariable;

                            c                char               char        cVariable;

                            i                  int                 int     iVariable;

                             s               short[int]         short[int]     sVariable;

                            l                   long[int]

                            u                 unsigned[int]

                             d                 double

                             f                 float

                            p                  pointer              void *   vpVariable;

                           v                   void                    void      vVariable;

                           st                  enum                   enum   A    stVariable;

                           st                  struct

                            st                  union

                            fp                 function  point      void(* fpGetModeFunList_a[] )(void)

                           后缀               数据类型                    示例

                          _a                   array  of               char     cVariable_a[TABLE_MAX];

                          _st    _pst                typedef   enum/struct/union      

                                                            typedef        structSM_EventOp

                                                                {

                                                                     unsignedchar

 

                                                                  } SM_EventOpt_st , *SM_EventOpt_pst ;

 

规则9、 变量命名   使用名词性词组;

            函数命名    使用动词性词组;

规则12、所有宏定义、枚举常数、只读变量  全用大写字母命名,用下划线分割单词。

规则14、结构体被定义时必须有明确的结构体名。

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3