#argument:它被预处理翻译为argument
##:把自己两边的符号连接成一个符号
1 #include<stdio.h> 2 3 static int global_status_1 = 0; 4 static int global_status_2 = 0; 5 6 #define MY_PRINT(FORMAT, VALUE) 7 printf("The value of " #VALUE " is " FORMAT " ", VALUE) 8 9 #define UPDATE_GLOBAL_STATUS(INDEX, VALUE) 10 (global_status_ ## INDEX = VALUE); 11 printf("global_status_"#INDEX " is %d ", global_status_ ## INDEX ) 12 13 int main() 14 { 15 int x = 5; 16 MY_PRINT("%d",x+10); 17 UPDATE_GLOBAL_STATUS(1, 5); 18 UPDATE_GLOBAL_STATUS(2, 6); 19 printf("global_status_1=%d ", global_status_1); 20 printf("global_status_2=%d ", global_status_2); 21 } 22 #include<stdio.h> 23 24 static int global_status_1 = 0; 25 static int global_status_2 = 0; 26 27 #define MY_PRINT(FORMAT, VALUE) 28 printf("The value of " #VALUE " is " FORMAT " ", VALUE) 29 30 #define UPDATE_GLOBAL_STATUS(INDEX, VALUE) 31 (global_status_ ## INDEX = VALUE); 32 printf("global_status_"#INDEX " is %d ", global_status_ ## INDEX ) 33 34 int main() 35 { 36 int x = 5; 37 MY_PRINT("%d",x+10); 38 UPDATE_GLOBAL_STATUS(1, 5); 39 UPDATE_GLOBAL_STATUS(2, 6); 40 printf("global_status_1=%d ", global_status_1); 41 printf("global_status_2=%d ", global_status_2); 42 }
Output:
The value of x+10 is 15
global_status_1 is 5
global_status_2 is 6
global_status_1=5
global_status_2=6