我没有写C很长时间,所以我不确定我应该怎么做这些递归的东西...我希望每个单元格包含另一个单元格,但我得到一个错误沿着"田地'孩子'的行具有不完整的类型".这是怎么回事?
typedef struct Cell {
int isParent;
Cell child;
} Cell;
Run Code Online (Sandbox Code Playgroud) extern int ether_hostton (__const char *__hostname, struct ether_addr *__addr)
__THROW;
Run Code Online (Sandbox Code Playgroud)
我在Linux机器上的/usr/include/netinet/ether.h中找到了上面的函数定义.
有人可以在const(关键字),addr(标识符)和最后__THROW前面解释双下划线的含义.
是否可以定义一个带有指向该类型结构的指针的结构?我的意思是:
typedef struct {
char* name;
node* parent;
} node;
Run Code Online (Sandbox Code Playgroud)
就我尝试或阅读而言,我不知道该怎么做或者甚至可能.
听起来很复杂,但这是一个简单的概念.假设你有一些结构"foo",如果它的成员是指向另一个foo结构的指针(如链表)
这似乎有效.
struct foo {
struct foo* ptr;
};
Run Code Online (Sandbox Code Playgroud)
但是,如果我想让foo成为一个类型呢?
就像我将如何做以下几点?
typedef struct foo {
foo* ptr;
} foo;
Run Code Online (Sandbox Code Playgroud)
ptr的声明失败,因为foo还不是限定符.
我想声明一个自引用结构,如下所示
typedef struct
{
entry_t *entry;
node_t *next;
}node_t;
Run Code Online (Sandbox Code Playgroud)
而不是链接列表的下面
struct node
{
entry_t *entry;
struct node *next;
}*head;
Run Code Online (Sandbox Code Playgroud)
这在C中有用吗?如果不是为什么不呢?
#include <stdio.h>
#include <stdlib.h>
#define MAX_ELEMENT 100
typedef struct TreeNode{
int weight;
TreeNode *left_child;
TreeNode *right_child;
} TreeNode;
typedef struct element{
TreeNode *ptree;
int key;
} element;
typedef struct HeapType{
element heap[MAX_ELEMENT];
int heap_size;
} HeapType;
Run Code Online (Sandbox Code Playgroud)
我得到了错误:
error: unknown type name ‘TreeNode’
TreeNode *left_child;
error: unknown type name ‘TreeNode’
TreeNode *right_child;
Run Code Online (Sandbox Code Playgroud)
我不明白为什么……你能解释一下吗?