Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C: field has incomplete type

Tags:

c

makefile

I apologise if this has been previously asked.

I am getting the following error while compiling through 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

like image 659
Sunny Avatar asked Jun 25 '13 07:06

Sunny


People also ask

Does C have incomplete type?

The error means that you try and add a member to the struct of a type that isn't fully defined yet, so the compiler cannot know its size in order to determine the objects layout. In you particular case, you try and have struct Cat hold a complete object of itself as a member (the mother field).

What are incomplete types in C?

An incomplete type is a type that describes an identifier but lacks information needed to determine the size of the identifier. An incomplete type can be: A structure type whose members you have not yet specified. A union type whose members you have not yet specified.

What does it mean incomplete type in c++?

An incomplete class declaration is a class declaration that does not define any class members. You cannot declare any objects of the class type or refer to the members of a class until the declaration is complete.


2 Answers

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

Is header included after struct ipsec_state?:

/* a.h */

struct a {
    int i;
};

/* demo.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
like image 140
David Ranieri Avatar answered Oct 20 '22 11:10

David Ranieri


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.

like image 31
szxk Avatar answered Oct 20 '22 09:10

szxk