错误:取消引用指向不完整类型的指针

时间:2016-05-13 13:37:27

标签: c linux

我的结构定义为

50 struct nf_hook_state {
51         unsigned int hook;
52         int thresh;
53         u_int8_t pf;
54         struct net_device *in;
55         struct net_device *out;
56         struct sock *sk;
57         struct net *net;
58         struct list_head *hook_list;
59         int (*okfn)(struct net *, struct sock *, struct sk_buff *);
60
};

在我的代码中,我试图按如下方式访问它:

unsigned int
my_packet_pass_through_hook(void *priv,
                        struct sk_buff *skb,
                        const struct nf_hook_state *state)
{
switch(state->hook){

编译时,它给了我错误:

error: dereferencing pointer to incomplete type ‘const struct nf_hook_state’ switch(state->hook){ 

有人会建议我在这里做错了吗?

1 个答案:

答案 0 :(得分:2)

您需要#include包含nf_hook_state struct的头文件,否则编译器在编译该翻译单元时不知道该struct的布局。

如果它不在特定标题中,则应该相应地重构代码。

相关问题