文章目录
0x1 typedef 的一个重要用途是定义机器无关的类型
#if __SIZEOF_POINTER__ == 4
typedef long double REAL;
#elif __SIZEOF_POINTER__ == 8
typedef double REAL;
#endif
0x21 给变量定义一个易于记忆且意义明确的新名字
typedef unsigned int UINT;
// 给 uint32_t 重新定义为 KERNEL_REGISTER,方便用户使用
typedef uint32_t KERNEL_REGISTER;
0x22 typedef 与 struct 结合
// typedef 与 struct 结合
/// 第一种情况
struct MyStruct {
int data1;
char data2;
};
typedef struct MyStruct newtype;
newtype a, b;
/// 第二种情况
typedef struct {
int data1;
char data2;
} newtype;
newtype a, b;
/// 第三种情况【常用】
typedef struct MyStruct {
int data1;
char data2;
} newtype;
newtype a, b;
0x3 使用 typedef 简化一些比较复杂的类型声明
通常,当函数的参数是一个回调函数时,就可能会使用 typedef 来简化声明
typedef int (*pFunc)(int, int);
int ADD(int a, int b)
{
return a + b;
}