Thread: Getting *pointer problem/error

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    39

    Getting *pointer problem/error

    Hello

    I having problem with fd_set pointer.....

    1st attempt:

    test.h :
    Code:
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netinet/tcp.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    #include <sys/time.h>
    #include <errno.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <signal.h>
    #include <netdb.h>
    #include <ctype.h>
    
    void testfdset(fd_set *test)
    {
    	FD_ZERO((struct fdset) &test);
    }
    test.c :
    Code:
    #include "test.h"
    
    int main()
    {
    	fd_set testing;
    	
    	testfdset(&testing);
    	
    	return 0;
    }
    Error shown:
    Code:
    $ gcc test.c
    In file included from test.c:1:0:
    test.h: In function ‘testfdset’:
    test.h:18:2: error: conversion to non-scalar type requested

    2nd attempt

    test.h :
    Code:
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netinet/tcp.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    #include <sys/time.h>
    #include <errno.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <signal.h>
    #include <netdb.h>
    #include <ctype.h>
    
    void testfdset(fd_set *test)
    {
    	FD_ZERO((struct fdset *) &test);
    }
    test.c :
    Code:
    #include "test.h"
    
    int main()
    {
    	fd_set testing;
    	
    	testfdset(&testing);
    	
    	return 0;
    }
    Error shown:
    Code:
    $ gcc test.c
    In file included from test.c:1:0:
    test.h: In function ‘testfdset’:
    test.h:18:2: error: dereferencing pointer to incomplete type
    Any solution to the pointer or reference problem?

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    The manual page perhaps?
    -- Macro: void FD_ZERO (fd_set *SET)
    This macro initializes the file descriptor set SET to be the empty
    set.
    It seems like a pointer to me, so perhaps it's just
    Code:
    void testfdset(fd_set *test)
    {
    	FD_ZERO(test);
    }
    Oh, and putting code in header files is almost always a bad idea.
    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.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by draggy View Post

    Code:
    void testfdset(fd_set *test)
    {
    	FD_ZERO((struct fdset) &test);
    }
    The problem is that FD_ZERO takes a pointer to a fd_set and you are already providing a pointer to your testfdset function. Therefor when you add the ampersand you get the address of the pointer, not the address of test.

    Code:
    void testfdset(fd_set *test)
    {
        FD_ZERO(test);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with pointer to a pointer variable
    By Rodri in forum C Programming
    Replies: 2
    Last Post: 11-20-2011, 10:50 AM
  2. Replies: 4
    Last Post: 10-31-2009, 07:18 PM
  3. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 08:53 PM
  4. Replies: 4
    Last Post: 11-05-2006, 02:57 PM
  5. pointer to pointer how do i solve following problem?
    By kobra_swe in forum C Programming
    Replies: 5
    Last Post: 07-19-2006, 04:49 PM