Chinaunix首页 | 论坛 | 博客
  • 博客访问: 88281
  • 博文数量: 60
  • 博客积分: 4002
  • 博客等级: 中校
  • 技术积分: 645
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 18:11
文章分类

全部博文(60)

文章存档

2011年(60)

我的朋友

分类: C/C++

2011-03-30 22:23:11

In general, typedefs are preferred, in part because they can correctly encode pointer types. For example, consider these declarations:

typedef char *String_t;
    #define String_d char *
    String_t s1, s2;
    String_d s3, s4;



s1, s2, and s3 are all declared as char *, but s4 is declared as a char, which is probably not the intention.
#defines do have the advantage that #ifdef works on them . On the other hand, typedefs have the advantage that they obey scope rules (that is, they can be declared local to a function or block).

 

阅读(312) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~