【发布时间】:2014-11-23 16:15:06
【问题描述】:
我试图了解一段代码中的结构用法。这让我很困惑。看起来 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;
【问题讨论】:
-
tour_struct是一个结构。tour_t是一个tour_struct *,也就是说,tour_t是一个指向被定义为tour_struct的结构体的指针 -
请注意,end in
_tare reserved on POSIX systems 的名称。此外,将指针类型命名为*_t充其量是不正当的。