typeof是gcc对于标准c的一个扩展,用来获取变量的类型。请看下面的例子:
#include <stdio.h>
int main()
{
char* ptr = NULL;
typeof(*ptr) chr = 'w';
printf("%c/n", chr);
return 0;
}
编译并执行:
[root@localhost typeof_test]# gcc -o test_typeof test_typeof.c
[root@localhost typeof_test]# ls
test_typeof test_typeof.c
[root@localhost typeof_test]# ./test_typeof
w
上面的例子中,ptr是char*类型,*ptr就是char类型,用typeof来获取类型后,定义变量
chr,等同于char chr = 'w';
2200

被折叠的 条评论
为什么被折叠?



