C/C++ 宏命令的神奇用法. 先看下面三条语句: #define Conn(x,y) x##y#define ToChar(x) #@x#define ToString(x) #x 1. ## 连接操作符##表示连接(token pasting, or token concatenation,merge two tokens into one while expanding macros).x##y表示什么?表示x连接y,举例说: int n = Conn(123,456…
语句表达式的亮点在于定义复杂功能的宏.使用语句表达式来定义宏,不仅可以实现复杂的功能,而且还能避免宏定义带来的歧义和漏洞.下面以一个简单的最小值的宏为例子一步步说明. 1.灰常简单的么,使用条件运算符就能完成,不就是 #define MIN(x,y) x > y ? y : x 当然这是最基本的 C 语言语法,可以写一个测试程序,验证一下我们定义的宏的正确性 #include <stdio.h> #define MIN(x,y) x < y ? y : x int main(int…
1.Preprocessor Glue: The ## Operator 预处理连接符:##操作符 Like the # operator, the ## operator can be used in the replacement section of a function-like macro.Additionally, it can be used in the replacement section of an object-like macro. The ## operator co…
c语言支持可变参数函数.这里的可变指,函数的参数个数可变. 其原理是,一般情况下,函数参数传递时,其压栈顺序是从右向左,栈在虚拟内存中的增长方向是从上往下.所以,对于一个函数调用 func(int a, int b, int c); 如果知道了参数a的地址,那么,可以推导出b,c的地址 #include <stdio.h> void test(int a, int b, int c) { printf("%p, %p, %p\n", &a, &b, &…