dereferencing pointer to incomplete type2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shridharpandey
    New Member
    • Oct 2008
    • 2

    #1

    dereferencing pointer to incomplete type2

    Hello all of u .. well i was trying to compile the iscsi module over ma system whn i was faced with this error .. the code segment is as under

    Code:
    int
    cnv_inet_to_string(struct sockaddr *ip_address, char *ip_string,
    		   char *port_string)
    {
    	__u8 *ptr;
    	__u32 k;
    	int i, c;
    
    	if (ip_address == NULL) {
    		i = -EINVAL;
    	} else if (ip_address->sa_family == AF_INET) 
    	{
    		[B]ptr = (__u8 *)&((struct sockaddr_in *)ip_address)->sin_addr.s_addr;[/B]  //Dereferencing Pointer to incompete type
    		for (i = 0; i < 3; i++) {
    			ip_string += sprintf(ip_string, "%u.", *ptr++);
    		}
    		sprintf(ip_string, "%u", *ptr);
    		sprintf(port_string, "%u",
    			ntohs(((struct sockaddr_in *)ip_address)->sin_port));
    		i = AF_INET;
    	} else if (ip_address->sa_family == AF_INET6) {
    		ptr = (__u8 *)((struct sockaddr_in6 *)ip_address)
    			->sin6_addr.s6_addr;
    		c = '[';
    		for (i = 0; i < 8; i++ ) {
    			k = *ptr++ << 8;
    			k += *ptr++;
    			ip_string += sprintf(ip_string, "%c%x", c, k);
    			c = ':';
    		}
    		sprintf(ip_string, "]");
    		sprintf(port_string, "%u",
    			ntohs(((struct sockaddr_in6 *)ip_address)->sin6_port));
    		i = AF_INET6;
    	} else {
    		strcpy(ip_string, "Unknown protocol family");
    		i = -EPFNOSUPPORT;
    	}
    	return i;
    }
    So some1 plzz suggest me wat shd i do to get rid of this **** ....
    Last edited by JosAH; Oct 19 '08, 08:06 AM. Reason: added [code] ... [/code] tags
  • shridharpandey
    New Member
    • Oct 2008
    • 2

    #2
    _u8 *ptr;
    ptr = (__u8 *)&((struct sockaddr_in *)ip_address)->sin_addr.s_add r;

    Why is this showing dereferencing pointer to incomplete type????

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      @shridharpandey : I split your posts from the old thread you posted your questions
      in; don't hijack other threads for your question, no matter how old they are and
      no matter how similar your question is to another question. Also add code tags
      around your code for readability reasons. And please use proper spelling if you
      want to be taken seriously.

      kind regards,

      Jos

      ps. I added those code tags for you this time.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Also note that we don't allow swearing on this site, please read our posting guidelines.


        Dereference to an incomplete type usually means that the compiler is aware that a structure of a given name exists but has no visibility of that structure of that structure. This most often happens when a structure name is forward declared and then the header the structure is defined in is accidentally not included.

        For example suppose the file Example.h contains the following

        Code:
        #ifndef EXAMPLE_H_INCLUDED
        #define EXAMPLE_H_INCLUDED
        
        struct Example {
            int someData;
        };
        
        #endif
        Then suppose a file main.c contained the following

        Code:
        struct Example; // Forward declaration of struct Example
        
        extern Example *GetExample();
        extern void ReleaseExample(Example *ex);
        
        int main(int argc, char *argp[])
        {
            Example *ex = GetExample();
        
            ex->someData = 6;
        
            ReleaseExample(ex);
        
            return 0;
        }
        Supposing that GetExample and ReleaseExample are defined in another file somewhere you would get a 'dereferencing pointer to incomplete' type error on line 10. This would be solved by including the file with the declaration of struct Example rather than forward declaring it.

        Comment

        Working...