typedef

用于简化声明

typedef struct {
  int age;
  char *name;
} Simple;

//然后可以
Simple x;
typedef char *ptr_to_char;
//然后可以
ptr_to_char a;

define陷阱:

char *a, b; //表示a是指针,b不是
  
#define ptr_to_char char *
ptr_to_char a, b; //a是指针,b不是

typedef char * ptr_to_char;  
ptr_to_char a, b; //a,b都是指针

Last updated

Was this helpful?