Thursday, August 31, 2006

typedef and #define

In general, typedefs are preferred, in part because they can correctly encode pointer types

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
#defines do have the advantage that #ifdef works on them
typedefs have the advantage that they obey scope rules (that is, they can be declared local to a function or block).

No comments:

Post a Comment