typedef 与 define的区别体现在两个方面
1.define可以对定义的宏类型名进行扩展,而typedef不可以
- #define peach int
- unsigned peach i;
- typedef int peach;
- unsiged peach i;
define关键字只是简单的字符替换,而typedef可以看成是对类型的一种封装,为现有类型取个新名字。
2在连续几个变量的声明中只有typedef可以保证类型的一致性
- #define int_ptr int *;
- int_ptr chalk,cheese;
chalk为int *类型,而cheese为int型。因为define只是简单的字符串替换
typedef的特殊使用方式