我试图理解一段代码中的结构用法。这让我很困惑。看起来 typedef 在同一个结构上使用了两次。请任何人都可以帮助我理解为什么这段代码有两次 typedef 。有什么办法可以简化这段代码吗? 非常感谢您抽出时间。
typedef struct {
city_t* cities;
int count;
cost_t cost;
} tour_struct;
typedef tour_struct* tour_t;
typedef struct {
tour_t* list;
int list_sz;
int list_alloc;
} stack_struct;
typedef stack_struct* my_stack_t;
最佳答案
第一个 typedef
为(匿名)结构提供类型名。第二个 typedef
定义了指向另一个的指针类型。
tour_struct tour; // declares a struct.
tour_t ptr; // declares a pointer to a struct.
关于c - typedef 在同一结构上使用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27091127/