为什么要结构名称有一个typedef? [英] Why should structure names have a typedef?

查看:138
本文介绍了为什么要结构名称有一个typedef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过源$ C ​​$ CS总是有一个结构的typedef到处都使用相同的,而不是使用结构名称定为结构的sname等直接?

I have seen source codes always having a typedef for a structure and using the same everywhere instead of using the structure name as "struct sname" etc directly?

什么是这背后的原因是什么?是否有任何优势,在这样做呢?

What is the reason behind this? Are there any advantages in doing this?

推荐答案

它更容易阅读 B盒; 结构boxtype b ;

Its easier to read Box b; than struct boxtype b;

typedef struct _entry{
   char *name;
   int id;
} Entry, *EntryP;

优点:结果
在上面的的typedef ,无论输入&安培; EntryP 结构_entry 定义分开。结果
因此, EntryP了firstEntry 可以在结构_entry *了firstEntry 的使用,是一个稍微简单一点来分析。

Advantage:
In the above typedef, both Entry & EntryP are defined apart from struct _entry.
So, EntryP firstentry can be used in place of struct _entry *firstentry and is a little simpler to parse in mind.

注意:它不会像结构名称的typedef 独立非执行董事,但很显然,它更容易阅读。另外,使用输入* VS EntryP 完全取决于用户。

Note: Its not like structure names should be typedefined, but evidently its easier to read. Also, use of Entry * vs EntryP is totally user-dependent.

这篇关于为什么要结构名称有一个typedef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆