#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    2
    Rep Power
    0

    Void Pointer in struct


    Kindly explain why this does not work?

    void fn(void ** data)
    {
    typedef struct{
    void *data_ptr;
    long long recv_time;
    }DataStruct;
    DataStruct *data_struct;

    data_struct->data_ptr = *data;
    }

    I get the following error:
    `void*' is not a pointer-to-object type

    I want to assign *data to data_ptr
    How else can I do this?
    Thanks
    Vijay
  2. #2
  3. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    The code looks fine to me with two exceptions. This line doesn't make any sense:

    long long recv_time;

    Did you mean to use the Windows LONGLONG data type?

    Also, this line:

    data_struct->data_ptr = *data;

    is fine with exception that it is accessing a member of a structure through a pointer that has not been initialized to point to a structure, yet. If the pointer is initialized, the above line is ok. There is no type mismatch. What compiler are you using?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    2
    Rep Power
    0
    long long is the type of the rd timestamp counter that i need.
    It works fine to me.
    Thanks for pointing out the initialization.
    I did a malloc and now things are working fine
    Thanks
    Vijay
  6. #4
  7. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    long long is supported by some compilers and is typically a 64bit integer. Th ISO/ANSI C (C99) specifies long long, but currently ISO/ANSI C++ does not(or if it does it is more recent that any reference I have checked)

    Clifford
  8. #5
  9. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    Addressing the original question. It compiles fine in MinGW/GCC 3.2 with max warning level and -ansi -pedantic options.

    A cast may remove the problem:

    Code:
        data_struct->data_ptr = (void*)*data;
    But without using your specific compiler I cannot test it. It is a good idea to specify the compiler and compiler version, and to post the compile log.

    Clifford
  10. #6
  11. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    Originally posted by krvijay
    Thanks for pointing out the initialization.
    I did a malloc and now things are working fine
    So, now that you perform a malloc(), the compiler doesn't complain? That doesn't make any sense. The compiler should treat that assignment statement the same regardless if you use malloc() before it or not.

    clifford, thanks for the info re: long long. I did not know that.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    109
    Rep Power
    12
    Ya, I was going to post that the problem was you wern't allocating memory, but the error message threw me off...

IMN logo majestic logo threadwatch logo seochat tools logo