error: dereferencing pointer to incomplete type

This is a discussion on error: dereferencing pointer to incomplete type within the C Programming forums, part of the General Programming Boards category; What the does this error mean its so frustrating. basically i have a struct created in main Code: struct Ethfrm_t ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    error: dereferencing pointer to incomplete type

    What the does this error mean its so frustrating.
    basically i have a struct created in main
    Code:
    struct Ethfrm_t
    {
    	struct FCfrm_t* ptr;
    	struct FIPfrm_t* FIPptr;
    	unsigned char DestEthAdr[6];
    	unsigned char SrcEthAdr[6];
    	UINT32  VLAN_HdrSave;
    	UINT32  reserved;
    	UINT32  pad;
    	unsigned char Ethbuffer[BUF_SIZE];
    }  __attribute__ ((packed));
    then i have
    typedef struct Ethfrm_t Ethfrm_t; On a header file on the top of most header files

    but when i made a functions file *.c When i use that Struct i get that warning all the time

    Code:
    void printEthfrm(Ethfrm_t * Ethfrm){
    	unsigned char* etherhead = Ethfrm->Ethbuffer;                ////right here
     	printf("EtherType error ");
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Basically it means that at the point where you attempt to use that struct, the compiler does not have a definition of the struct available to it. You said that you've got the typedef in the header but the struct definition itself is in some other source file (with main function)? The definition should be in the header if you're going to use it in multiple files.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    Okay well this is retarded but now i put it in a header
    Code:
    typedef struct Ethfrm_t
    {
    	struct FCfrm_t* ptr;
    	struct FIPfrm_t* FIPptr;
    	unsigned char DestEthAdr[6];
    	unsigned char SrcEthAdr[6];
    	UINT32  VLAN_HdrSave;
    	UINT32  reserved;
    	UINT32  pad;
    	unsigned char Ethbuffer[BUF_SIZE];
    }  __attribute__ ((packed)) Ethfrm_t;
    I get this error
    server.h:11: error: redefinition of ‘struct Ethfrm_t’
    server.h:20: error: redefinition of typedef ‘Ethfrm_t’
    server.h:20: error: previous declaration of ‘Ethfrm_t’ was here
    iono what its problem is but i doesnt like me putting Ethfrm_t on the top and bottom????? Y

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by kiros88 View Post
    Okay well this is retarded but now i put it in a header
    Did you put it anywhere else as well?

    IF NOT: I don't use the same name at both ends; it shouldn't matter I think but if that fixes it, then there you go.
    Last edited by MK27; 09-16-2009 at 03:12 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,023
    That sounds like you are including the same header more than once. That's fine to do from a style perspective, but you need include guards to prevent the compiler from reading the same code twice. I'll let someone else post a link on include guards, or you can just google.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 02:17 PM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Glib and file manipulation
    By unixOZ in forum Linux Programming
    Replies: 1
    Last Post: 03-22-2004, 08:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21