前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >typeof关键字的作用

typeof关键字的作用

作者头像
233333
发布2018-03-07 15:49:35
9450
发布2018-03-07 15:49:35
举报

一、typeof详解:

前言:     typeof关键字是C语言中的一个新扩展,这个特性在linux内核中应用非常广泛。(其实这和C++的auto关键字和可以推断decltype关键字相当类似)

二、实例:

      1,把y定义成x指向的数据类型:

      typeof(*x) y;

   2,把y定义成x指向数据类型的数组:

      typeof(*x) y[4];

   3,把y定义成一个字符指针数组:               typeof(typeof(char *)[4] y;       这与下面的定义等价:               char *y[4];

   4,typeof(int *) p1,p2; /* Declares two int pointers p1, p2 */               int *p1, *p2;

   5,typeof(int) *p3,p4;/* Declares int pointer p3 and int p4 */               int *p3, p4;

   6,typeof(int [10]) a1, a2;/* Declares two arrays of integers */               int a1[10], a2[10];

三,局限

typeof构造中的类型名不能包含存储类说明符,如externstatic。不过允许包含类型限定符,如constvolatile。    例如,下列代码是无效的,因为它在typeof构造中声明了extern:         typeof(extern int) a;

四,参考博客

1,http://blog.csdn.net/wslong/article/details/7728811   

2,http://gcc.gnu.org/onlinedocs/gcc/Typeof.html#Typeof

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-11-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、typeof详解:
    • 二、实例:
      • 三,局限
        • 四,参考博客
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档