C
变量的命名规则
作用域前缀,
No. | 标识符类型 | 作用域前缀 |
---|---|---|
1 | Global Variable | g |
2 | File Static Variable(native) | n |
3 | Function Static Variable | f |
4 | Auto Variable | a |
5 | Global Function | g |
6 | Static Function | n |
数据类型前缀命名规则,
No. | Prefix | Suffix | Data Type | Example | Remark |
---|---|---|---|---|---|
1 | bt | bit | Bit btVariable; | ||
2 | b | boolean | boolean bVariable; | ||
3 | c | char | char cVariable; | ||
4 | i | int | int iVariable; | ||
5 | s | short[int] | short[int] sVariable; | ||
6 | l | long[int] | long[int] IVariable; | ||
7 | u | unsigned[int] | unsigned[int] uiVariable; | ||
8 | d | double | double dVariable; | ||
9 | f | float | float fVariable; | ||
10 | p | pointer | void * vpVariable; | 指针前缀 | |
11 | V | void | void vVariable; | ||
13 | st | enum | enum A stVariable; | ||
14 | st | struct | struct A stVariable; | ||
15 | st | union | union A stVariable; | ||
16 | fp | function pointer | void(* fpGetModeFuncList_a[])( void ) | ||
17 | -a | array of | char cVariable_a[TABLE_MAX]; | ||
18 | _st,_pst | typedef enum/struct/union |
| 当自定义结构数据类型时使用_st 后缀; 当自定义结构数据类型为指针类型时使用_pst后缀 |
关键字
static
修饰全局变量,作用域仅限于变量被定义的文件中。从定义之处开始,到文件末尾结束。
静态局部变量,在函数体里面定义的,就只能在这个函数里用了。被 static 修饰的变量总是存在内存的静态区,即使这个函数运行结束,这个静态变量的值也不会被销毁。
修饰函数,表示静态函数,指对函数的作用域仅局限于本文件,不用担心自己定与你的函数是否会与其他文件中的函数同名。