1.常規變量類型定義
例如:typedef unsigned char uchar
描述:uchar等價於unsigned char類型定義 uchar c聲明等於unsigned char c聲明
2.數組類型定義
例如: typedef int array[2];
描述: array等價於 int [2]定義; array a聲明等價於int a[2]聲明
擴展: typedef int array[M][N];
描述: array等價於 int [M][N]定義; array a聲明等價於int a[M][N]聲明
3.指針類型定義
例如: typedef int *pointer;
描述: pointer等價於 int *定義;pointer p聲明等價於int *a聲明
例如: typedef int *pointer[M];
描述: pointer等價於 int *[M]定義 pointer p聲明等價於int *a[M]聲明明
4.函數地址說明
描述:C把函數名字當做函數的首地址來對待,我們可以使用最簡單的方法得到函數地址
例如: 函數:int func(void); unsigned long funcAddr=(unsigned long)func, funcAddr的值是func函數的首地址
5.函數聲明
例如: typedef int func(void); func等價於 int (void)類型函數
描述1: func f聲明等價於 int f(void)聲明,用於文件的函數聲明
描述2: func *pf聲明等價於 int (*pf)(void)聲明,用於函數指針的生命,見下一條
6.函數指針
例如: typedef int (*func)(void)
描述: func等價於int (*)(void)類型
func pf等價於int (*pf)(void)聲明,pf是一個函數指針變量
識別typedef的方法:
a).第一步。使用已知的類型定義替代typdef後面的名稱,直到只剩下一個名字不識別爲正確
b).第二步.未知名字爲定義類型,類型爲取出名稱和typedef的所有部分,
c).第三部.定義一個變量時,變量類型等價於把變量替代未知名字的位置所得到的類型