Thread: error: field has incomplete type

  1. #1
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342

    error: field has incomplete type

    I have these three structures:

    Code:
    typedef uint32_t      LINX_SPID;
    
    
    struct sockaddr_linx
    {
            sa_family_t family;
            LINX_SPID   spid;
    };
    
      typedef struct protocolstruct ProtocolStruct;
      struct protocolstruct
      {
          struct sockaddr_linx                     sin1,  
                                                  sin2;   
          int                                   nodelay; 
          struct hostent                            *addr;  
          int                                    sndbufsz, 
                                                  rcvbufsz; 
    #if defined(INFINIBAND)
          IB_mtu_t                        ib_mtu;  
          int                                    commtype; 
          int                                    comptype; 
    #endif
      };
    
    typedef struct argstruct ArgStruct;
    struct argstruct
    {
       ...
       <lots of other irrelevant declarations>
       struct protocolstruct prot;
    };

    But, when I run the program, I get the error
    Code:
     error: field 'prot' has incomplete type
    and it is pointing to the line in blue.
    The only thing that can cause problems in "prot" is
    struct sockaddr_linx sin1, sin2;
    But, the struct sockaddr_linx has been declared in the same file. Why am I getting this error?
    Last edited by kris.c; 06-12-2007 at 06:09 AM.
    In the middle of difficulty, lies opportunity

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I'm not sure about this, but what happens if you change this line:
    struct protocolstruct prot;
    to this:
    protocolstruct prot;

  3. #3
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Tried that , I get this message :
    Code:
    netpipe2.h:262: error: syntax error before 'ProtocolStruct'
    netpipe2.h:262: warning: no semicolon at end of struct or union
    netpipe2.h:264: warning: ISO C does not allow extra ';' outside of a function
    In the middle of difficulty, lies opportunity

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Are they all in the same header file?
    Are all the header file(s) included?
    Are they included in the right order?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Surprisingly, I removed the first member in the structure "protocol struct", I am still getting the same error. This is absurd..
    In the middle of difficulty, lies opportunity

  6. #6
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    There was a
    #ifdef(TCP) enclosing the whole protocol struct and I had to set the -DTCP flag when I tried to compile it
    :|
    In the middle of difficulty, lies opportunity

  7. #7
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Just out of curiosity,
    >Are they included in the right order?
    Does the order really matter. Is it compiler dependent? I have even noticed that I dont get any error/warning even if I include the same header file multiple times. Or is it got to do with the -Wall option?
    In the middle of difficulty, lies opportunity

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    58
    That's because all standard header have "locks"

    there like:

    Code:
    #ifndef __HEADER__
    #define __HEADER__
    
    code
    code
    code
    
    #endif

  9. #9
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Hmmm.. makes sense. What about re-declarations?
    In the middle of difficulty, lies opportunity

  10. #10
    Registered User
    Join Date
    May 2007
    Posts
    58
    Quote Originally Posted by kris.c View Post
    Hmmm.. makes sense. What about re-declarations?
    What do you mean by "re-declarations"?

    I get confused with declarations, definitions and etc :P

  11. #11
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Sorry.. I should have typed , multiple inclusions instead..
    In the middle of difficulty, lies opportunity

  12. #12
    root koodoo's Avatar
    Join Date
    Oct 2005
    Location
    a small village faraway in the mountains
    Posts
    28
    do you mean multiple inclusions of header files?
    they'll give you that "re-declarations" error that you mentioned.

    To prevent a file from being included multiple no. of times, you can use the #pragma once directive or you can also use #include guard bands.
    The #pragma directive is compilor specific (but I think #pragma once is supported by C99)
    Google for more information.

    regards,
    koodoo
    If this helped you, please take the time to rate the value of this post by clicking here.

    Statutory Warning : Beware of C... it's highly addictive.

    --------------------------------------------------------------
    Registered Linux User #388419
    --------------------------------------------------------------

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. arithmetic on pointer to an incomplete type?
    By Volair in forum C Programming
    Replies: 4
    Last Post: 11-19-2006, 06:53 PM
  3. typename madness
    By zxcv in forum C++ Programming
    Replies: 4
    Last Post: 05-13-2006, 10:35 PM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM