typedef定义类型

初心勿忘 2016-03-01 08:20:27
麻烦给解释下 typedef void List;
...全文
183 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-03-02
  • 打赏
  • 举报
回复
typedef typedef type-declaration synonym; The typedef keyword defines a synonym for the specified type-declaration. The identifier in the type-declaration becomes another name for the type, instead of naming an instance of the type. You cannot use the typedef specifier inside a function definition. A typedef declaration introduces a name that, within its scope, becomes a synonym for the type given by the decl-specifiers portion of the declaration. In contrast to the class, struct, union, and enum declarations, typedef declarations do not introduce new types — they introduce new names for existing types. Example // Example of the typedef keyword typedef unsigned long ulong; ulong ul; // Equivalent to "unsigned long ul;" typedef struct mystructtag { int i; float f; char c; } mystruct; mystruct ms; // Equivalent to "struct mystructtag ms;" typedef int (*funcptr)(); // funcptr is synonym for "pointer // to function returning int" funcptr table[10]; // Equivalent to "int (*table[10])();"
paschen 2016-03-02
  • 打赏
  • 举报
回复
用List作为void的别名 关键要明白typedef的用法,自然就明白了
lm_whales 2016-03-02
  • 打赏
  • 举报
回复
C,C++ void 类型,只是个方便的类型 不具有一般类型的特性 例如,不能定义 void 类型变量 这里把 List 定义为 void 估计只是想使用 void *,而不是 void 根据望名知意原则,标识符,特别是类型名,应该一看就知道是做什么的 List 显然是个表类型,个人认为,这样定义,可能是打算使用 void * 当然这只是猜测,必须看到源代码,才知道为何这么做
galiniur0u 2016-03-02
  • 打赏
  • 举报
回复
List只是void的别名而已,就像一个人的大名叫张三,而他的小名叫小张,这里的张三就是void,小张就是List。
引用 3 楼 lm_whales 的回复:
要看源码,不然 List 就是 void 这个答案,估计很难令人满意
大神,求问还有别的解释,可以举几个例子么?
遥哥_GB_Fore 2016-03-02
  • 打赏
  • 举报
回复
typedef void List 就是给void定义一个list这样的名字。就想你叫void,然后给你又起了个名字List。 void是一种无类型的数据结构,
lm_whales 2016-03-01
  • 打赏
  • 举报
回复
要看源码,不然 List 就是 void 这个答案,估计很难令人满意
  • 打赏
  • 举报
回复
见http://baike.baidu.com/link?url=jtD-QeAfVCOhSchQdQmKEKBXhW5SVuvAyLSc-sw80l4WEnkJzQ0Ux0opJKcvvRw3MG7KysiHcPlvhI7HfxnPDK
gh_99 2016-03-01
  • 打赏
  • 举报
回复
List 就是void List是void的别名.

69,370

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧