以下是MWE:
#include <stdlib.h>
typedef struct node_type {
struct node* next;
struct node* prev;
} node;
int main(int argc, char* argv[]) {
node* n = (node*)malloc(sizeof(node));
}
在 struct 体定义中,node*
之前没有struct
将出错; node
尚未定义.但是,struct node*
可以正常工作,尽管此时只定义了struct node_type
.为什么会这样?
直观地说,如果 struct 的字段定义为struct node_type*
,或者之前有显式的tyecif并且字段是node*
类型,它就会进行编译.然而,我不明白为什么内联typlef允许字段是类型struct node*
,而不是类型node*
.