nic*_*ael 2 c c++ macros objective-c c-preprocessor
定义宏时(例如#define BALL
).为什么人们使用大写字母?我可以写类似的东西#define ball
.它不是大写的,但它有效.
为什么使用_
长变量名?为什么不直接命名变量,a or b
因为它很容易理解和调试。
使用变量名TotalHeight
比 simple 更有意义i
。有些人甚至将数据类型作为前缀,例如Int_TotalHeight
. 它易于维护代码。
为了回答你的问题,人们使用它来获得更多的理解。通常
1)区分变量名和宏名
#define MAX 45 // easy to understand, it is a macro
int max=45;
Run Code Online (Sandbox Code Playgroud)
2)将功能与宏区分开来。说
#define MULT(x, y) (x) * (y)
int mult(int,int);
Run Code Online (Sandbox Code Playgroud)