C语言 C: 字段类型不完整

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17291268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:47:03  来源:igfitidea点击:

C: field has incomplete type

cmakefile

提问by Sunny

I apologise if this has been previously asked.

如果之前有人问过这个问题,我深表歉意。

I am getting the following error while compiling through make:

通过make编译时出现以下错误:

.../inc/intModIp.h:418: error: field 'cnc_id' has incomplete type
../inc/intModIp.h:419: error: field 'cnc_key' has incomplete type
../inc/intModIp.h:421: error: field 'fin_id' has incomplete type
../inc/intModIp.h:422: error: field 'fin_key' has incomplete type
../inc/intModIp.h:424: error: field 'remote_id' has incomplete type
../inc/intModIp.h:426: error: field 'cnc_ipsec_peer' has incomplete type
../inc/intModIp.h:427: error: field 'fin_ipsec_peer' has incomplete type
../inc/intModIp.h:428: error: field 'remote_ipsec_peer' has incomplete type
../inc/intModIp.h:430: error: field 'cnc_link' has incomplete type
../inc/intModIp.h:431: error: field 'cnc_esp' has incomplete type
../inc/intModIp.h:433: error: field 'fin_link' has incomplete type
../inc/intModIp.h:434: error: field 'fin_esp' has incomplete type

Respective code in the header file is as follows:

头文件中各自的代码如下:

#if 1 || defined(SYMB_IPSEC)
    struct ipsec_state {
        int enabled;
        int active;
        int timer;
/* IPSEC_SOCKET_STATES */

        struct ipsec_id cnc_id;
        struct ipsec_priv_key cnc_key;

        struct ipsec_id fin_id;
        struct ipsec_priv_key fin_key;

        struct ipsec_id remote_id;

        struct ipsec_peer cnc_ipsec_peer;
        struct ipsec_peer fin_ipsec_peer;
        struct ipsec_peer remote_ipsec_peer;

        struct ipsec_ike_link cnc_link;
        struct ipsec_esp_sa cnc_esp;

        struct ipsec_ike_link fin_link;
        struct ipsec_esp_sa fin_esp;
    } ipsec;
#endif

could someone please help me with this. Please let me know if any other information is required.

有人可以帮我解决这个问题吗?如果需要任何其他信息,请告诉我。

Thanks, Sunny

谢谢,阳光

采纳答案by David Ranieri

The problem could be that all those structs are declared forward.

问题可能是所有这些结构都是向前声明的。

Is header included after struct ipsec_state?:

标头是否包含在struct ipsec_state?之后:

/* a.h */

/* 啊*/

struct a {
    int i;
};

/* demo.c */

/* 演示.c */

struct b {
    struct a A;
};

#include "a.h"

int main(void)
{
    return 0;
}

Output:

输出:

david@debian:~$ gcc -std=c99 -Wall -pedantic -W -Wextra -o demo demo.c
demo.c:2:11: error: field ‘A' has incomplete type

回答by fatihk

Compiler can not find stated struct definitions (ipsec_id... ipsec_esp_sa), you may need to include related header files

编译器找不到声明的结构体定义(ipsec_id... ipsec_esp_sa),您可能需要包含相关的头文件

回答by szxk

One source of that error (field has incomplete type) is when you use the struct keyword in front of an alias(a variable defined through typedef). Try removing the struct keyword.

该错误的一个来源(字段类型不完整)是在别名(通过 typedef 定义的变量)前使用 struct 关键字。尝试删除 struct 关键字。

回答by Rajendra

put pointer for structure member.

放置结构成员的指针。

struct ipsec_state {
        int enabled;
        int active;
        int timer;
/* IPSEC_SOCKET_STATES */

        struct ipsec_id *cnc_id;
        struct ipsec_priv_key *cnc_key;

        struct ipsec_id *fin_id;
        struct ipsec_priv_key *fin_key;

        struct ipsec_id *remote_id;

        struct ipsec_peer *cnc_ipsec_peer;
        struct ipsec_peer *fin_ipsec_peer;
        struct ipsec_peer *remote_ipsec_peer;

        struct ipsec_ike_link *cnc_link;
        struct ipsec_esp_sa *cnc_esp;

        struct ipsec_ike_link *fin_link;
        struct ipsec_esp_sa *fin_esp;
    } ipsec;
#endif