void type pointers 
Author Message
 void type pointers

Can someone out there help me with this problem?  Void type pointers are
supposed to be generic enough to assign any data type to it.  
(void *pData)  I want to create a linked list of void type pointers but I
can't seem to figure out how to get different data types assigned to the void
type pointer.  Information on this is rare.  First of all, is it possible to
create a linked list of different data types assigned to a void type pointer?
Different data types have different sizes so how can this be done?  Then, how
can I get the information back even if I knew what the data type was?  Nothing
seems to work for me.  Please help.

-John Huber



Mon, 03 Dec 2001 03:00:00 GMT  
 void type pointers
Post your code. Your prose description of your code is not the problem. Your
code is the problem.

--

Paul Lutus
www.arachnoid.com

Quote:

>Can someone out there help me with this problem?  Void type pointers are
>supposed to be generic enough to assign any data type to it.
>(void *pData)  I want to create a linked list of void type pointers but I
>can't seem to figure out how to get different data types assigned to the
void
>type pointer.  Information on this is rare.  First of all, is it possible
to
>create a linked list of different data types assigned to a void type
pointer?
>Different data types have different sizes so how can this be done?  Then,
how
>can I get the information back even if I knew what the data type was?
Nothing
>seems to work for me.  Please help.

>-John Huber



Mon, 03 Dec 2001 03:00:00 GMT  
 void type pointers


Quote:
>Can someone out there help me with this problem?  Void type pointers are
>supposed to be generic enough to assign any data type to it.  

What is guaranteed is that you can convert any pointer to an object to
a void * pointer and back to the original type and you get the original
value back. Additionally in most cases casts aren't needed for the
conversions, the C compiler will perform them automatically.

Quote:
>(void *pData)  I want to create a linked list of void type pointers but I
>can't seem to figure out how to get different data types assigned to the void
>type pointer.

There are no guarantees about converting non-pointer types to void *,
or pointers to function types. Doing this is generally an error.

Quote:
> Information on this is rare.  First of all, is it possible to
>create a linked list of different data types assigned to a void type pointer?

You can use a void * pointer to point at an object of any type. Therefore
you can put a void * pointer in the linked list structure that points
at another object of any type. To access the object again you will
have to convert the void * pointer back to a pointer of the original
type. Sometimes all you need to do is view the object as an array of bytes
and you can view it as that by converting the void * pointer to
unsigned char *. You generally have to store a size as well in this case.
This is effectively how functions like memcpy(), fwrite() and qsort()
work internally.

Quote:
>Different data types have different sizes so how can this be done?  Then, how
>can I get the information back even if I knew what the data type was?  Nothing
>seems to work for me.  Please help.

I suggest you post a more specific example of what you want to do. Any code
you can give would also be helpful, even if just an outline. It may also
placate some regulars here. :-)

--
-----------------------------------------


-----------------------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 void type pointers


...

Quote:
>I suggest you post a more specific example of what you want to do. Any code
>you can give would also be helpful, even if just an outline. It may also
>placate some regulars here. :-)

I see I was too late. :-)

--
-----------------------------------------


-----------------------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 void type pointers

Quote:

> Can someone out there help me with this problem?  Void type pointers are
> supposed to be generic enough to assign any data type to it.

It is not clear in this post if you have a misconception or a problem expressing
yourself.  You can assign a POINTER to any data type to a void *.  Consider a
datum like the following for a start:

typedef struct {
   enum typeinfo t;     /* you create the enumeration elsewhere */
   void *p;             /* pointer to data */

Quote:
} datum;
> (void *pData)  I want to create a linked list of void type pointers but I
> can't seem to figure out how to get different data types assigned to the void
> type pointer.  Information on this is rare.  First of all, is it possible to
> create a linked list of different data types assigned to a void type pointer?
> Different data types have different sizes so how can this be done?  Then, how
> can I get the information back even if I knew what the data type was?  Nothing
> seems to work for me.  Please help.

> -John Huber

--

Ah! but it is something to have at least the
choice of nightmares.  - Joseph Conrad



Mon, 03 Dec 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. void pointer (void *) : how to determine type?

2. passing pointers of type void?

3. casting a structure type on a void pointer in the Watch window

4. Type-cast from a void pointer

5. from void (void*) to void (_cdecl*) (void*)

6. HRESULT return type turns into void when adding class from type library

7. Casting function pointer to void pointer

8. problem with pointer to pointer to void

9. pointers to functions and pointers to void.

10. pointer arithmetic with a pointer to void

11. Can void-pointers be casted to function-pointers?

12. Pointer-arithmatic and void pointers

 

 
Powered by phpBB® Forum Software