//test.c #include <stdio.h>
#include <stdlib.h> //字符串化运算符
#define EXPAND(name) ({ \
printf("%s\n", #name); }) //二元运算符 ## 将左和右操作数结合成一个记号 #define test(name, index) ( { \
int i, len = sizeof(name ## index) / sizeof(int); \
for (i = 0; i < len; i++) \
{ \
printf("%d\n", name ## index[i]); \
}}) int main(int argc, char *argv[]) {
EXPAND(Test);
EXPAND("\"TEST"); EXPAND(__DATE__);
EXPAND(__TIME__);
EXPAND(__FILE__);
EXPAND(__LINE__);
EXPAND(__func__);
int x1[] = { 1, 2, 3 };
int x2[] = { 11, 22, 33, 44, 55};
test(x, 1);
test(x, 2); return 0;
}
运行效果如下:
$ ./defind_test
Test
"\"TEST"
__DATE__
__TIME__
__FILE__
__LINE__
__func__