慕后森
typedef遵守范围规则就像变量一样,而define保持有效直到编译单元结束(或直到匹配undef)。此外,有些事情可以通过无法完成的事情typedef来完成define。例如:typedef int* int_p1;int_p1 a, b, c; // a, b, c are all int pointers#define int_p2 int*int_p2 a, b, c; // only the first is a pointer, because int_p2 // is replaced with int*, producing: int* a, b, c // which should be read as: int *a, b, ctypedef int a10[10];a10 a, b, c; // create three 10-int arraystypedef int (*func_p) (int);func_p fp; // func_p is a pointer to a function that // takes an int and returns an int