typeof关键字
2010-04-27 00:55
141 查看
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';
#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';
相关文章推荐
- GetType与C#关键字typeof ,is,as
- C扩展 typeof 关键字解释
- static、const、volatile、typeof关键字的用途描述
- C语言中的typeof关键字
- C语言中的typeof关键字(全文转载)
- GNU 中C语言 typeof关键字例解
- C 语言中 typeof 关键字简介
- typeof关键字
- typeof关键字简介
- C语言中的typeof关键字
- typeof关键字
- TypeScript 0.9.1 发布,新增 typeof 关键字
- C/C++,关键字typeof的用法
- __thread 和 __typeof__关键字
- typeof关键字简介
- C语言中的typeof关键字
- C#中的typeof关键字
- __thread 和 __typeof__关键字
- typeof关键字简介
- typeof关键字是C语言的应用