不
#define
is a preprocessor token: the compiler itself will never see it.
typedef
is a compiler token: the preprocessor does not care about it.
您可以使用其中的一种或另一种来达到相同的效果,但最好是根据您的需要使用适当的一种
#define MY_TYPE int
typedef int My_Type;
当事情变得"毛茸茸的"时,使用适当的工具就能使它变得正确.
#define FX_TYPE void (*)(int)
typedef void (*stdfx)(int);
void fx_typ(stdfx fx); /* ok */
void fx_def(FX_TYPE fx); /* error */