#include#define peach inttypedef int banana;int main(void){ unsigned peach a; unsigned banana b; return 0;}
上面的代码中,
unsigned banana b;
该行编译会出现错误。
因为typedef是一种彻底的“封装”类型,而#define只是简单的文本替换。
再看,
#include运行结果为:#define peach char*typedef char* banana;int main(void){ peach a,b; banana c,d; printf("sizeof(a)=%d\n",sizeof(a)); printf("sizeof(b)=%d\n",sizeof(b)); printf("sizeof(c)=%d\n",sizeof(c)); printf("sizeof(d)=%d\n",sizeof(d)); return 0;}
sizeof(a)=4 sizeof(b)=1 sizeof(c)=4 sizeof(d)=4