#include <stdio.h>
#define CONVERS(x) #x
//对#调用的使用
#define CALL(f,p) (printf("call function %s\n",#f),f(p))
#define NAME(n) name##n
#define STRUCT(type) typedef struct _tag_##type type;\
struct _tag_##type
STRUCT(Student)
(
int id;
);
int square(int n)
{
return n*n;
}
int f1(int x)
{
return x;
}
//#调用的强大之处。不仅可以实现字符串的调用,同时可以实现函数的调用
int main()
{
/*
HELLO WORLD
100
while
return
call function square
1.16
call function f1
2.10
*/
int NAME(1);// 预处理仅仅进行简单的粘连 在预编译里面实现的是int name1
Student s1;
int NAME(2);
NAME(1) = 1;
NAME(2) = 2;
printf("%d\n", NAME(1));
printf("%d\n", NAME(2));
printf("%s\n", CONVERS(HELLO WORLD));
printf("%s\n", CONVERS(100));
printf("%s\n", CONVERS(while));
printf("%s\n", CONVERS(return));
struct MyStruct {
int a;
};
printf("1.%d\n", CALL(square, 4));
printf("2.%d\n", CALL(f1, 10));
}
##号使用范围很广阔