typedef struct和指针

在学习链表时遇到了typedef已经用typedef定义的指针,不是很懂,某浪里有位博主的博文写的很详细,我直接粘过来 
假设我们定义一个结构体:

typedef  struct ANSWER_HEADER
{
    u8 u8Type;
    u8 u8Code;
    u32 u32TimeStamp;
    struct ANSWER_HEADER *pNext;
}ANSWER_HEADER_T, *PANSWER_HEADER_T;

ANSWER_HEADER为结构名,这个名字主要是为了在结构体中包含自己为成员变量的时候有用(因为执行到第6行时,别名还没有被编译,所以第6行只能用结构名来定义指向这个结构的指针.
ANSWER_HEADER_T为struct ANSWER_HEADER的别名 
PANSWER_HEADER_T为struct ANSWER_HEADER*的别名

上面的定义方式等价于

struct ANSWER_HEADER
{
    u8 u8Type;
    u8 u8Code;
    u32 u32TimeStamp;
    struct ANSWER_HEADER *pNext;
};
typedef  struct ANSWER_HEADER ANSWER_HEADER_T;
typedef  struct ANSWER_HEADER *PANSWER_HEADER_T;

之后就可以用ANSWER_HEADER_T和PANSWER_HEADER_T来定义变量,如

PANSWER_HEADER_T L;//定义了一个指向ANSWER_HEADER的指针L

相当于

ANSWER_HEADER *L;

传送门:typedef struct和指针 - L4EX的博客 - CSDN博客 

https://blog.csdn.net/u013814701/article/details/52996544  

ref:【C语言】23-typedef - M了个J - 博客园 https://www.cnblogs.com/mjios/archive/2013/03/24/2979482.html

posted @ 2019-06-08 09:12  西伯利亚虎  阅读(2533)  评论(0编辑  收藏  举报

Permanence, perseverance and persistence in spite of all obstacles, discouragements and impossibilities: It is this, that in all things distinguishes the strong soul from the weak.