<分区>
我是先这样写代码的
typedef struct
{
struct Node *next;
int data;
} Node;
因为我了解到我可以编写 struct
而无需像这样在 struct
旁边编写 Node
(如果我使用 typedef
)
typedef struct Node
{
struct Node *next;
int data;
} Node;
但是如果我在没有 Node
的情况下编写,稍后当我使用 Node *cur = head->next
之类的代码时会出现警告
警告标志是:
'warning: incompatible pointer types initializing 'Node *' with an expression of type 'struct Node *''
(仅供引用,我使用 mac os 和 visual studio 代码)
我知道如何解决这个问题,但我不知道为什么之前的代码在某些编译器中有效,而在其他一些编译器中却无效。
定义struct
的最佳方式是什么?是否推荐使用 typedef
?