typedef基本数据类型
typedef int a;
a abc;
后面的a abc
就等价于int abc
typedef结构体
typedef
struct a {int a;int b;
}
abc;abc aaa;
对于上述,abc aaa;
就等价于struct a aaa;
简而言之,typedef的本质,就是构建等价关系。
第一个例子,让a
和int
等价;
第二个例子,让abc
和struct a { int a; int b; };
等价;
这样一来,简化书写。
不过也有特别的例子,就是使用数组的时候。
typedef数组
typedef int a[5];
a aa;
这里a aa
等价于int aa[5]
,这里aa的本质,是具有5个元素的int类型数组。
也就是说,typedef int a[5];
,使得a
与int[5]
等价,当然C语言没有这样的写法,希望能够理解,a
就是代表具有5个int类型元素的数组。
typedef struct desc_struct
{ unsigned long a, b;
}
desc_table[256];desc_table idt, gdt;
这里idt
就是struct desc_struct idt[256]
,gdt
同理。