求细说一下typedef的理解,表示不太懂

C语言 码拜 8年前 (2016-04-05) 877次浏览
新手还在高中,,表示这个东西没太看懂,,,本人给一段代码看看吧,,,
一个链栈里面,,有一个
struct stack_node
{

};
typedef struct stack_node stack_list;
typedef stack_list *slink;
这里面的这个结构体类型是干什么用的
麻烦看看,,感激不尽
解决方案

10

typedef给指定类型起一个别名

10

就是以后定义结构体变量时直接用后面那个别名定义声明就好

30

typedef struct stack_node stack_list;表示可以用stack_list替代struct stack_node
如:stack_list a等同于struct stack_node a;
typedef stack_list *slink;可以用slink替代stack_list *(注意*是跟着stack_list的)
如:stack_list *a等同于slink a;
http://www.cnblogs.com/afarmer/archive/2011/05/05/2038201.html

15

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])();”

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求细说一下typedef的理解,表示不太懂
喜欢 (0)
[1034331897@qq.com]
分享 (0)