Roman Mashak said:
I apologize, gentlemen, but I misled you. I expressed myself with
ambiguity and need to correct now. What I really want is 'void *data'
member to store
_pointers_ to objects of various types (say, 'int', 'long', 'char' in
the first place), I confused two terms 'object' and 'pointer to
object'.
In which case this is (a) easy and (b) probably pointless. void * can
point to any object type without any problem:
#include <stdlib.h>
struct llnode
{
void *data;
struct llnode *next;
};
/* llnode_add - adds a new node to a linked list. A pointer to the
existing head of the list is passed in (or NULL if the list is
currently empty). The new node becomes the new head of the list,
and a pointer to it is returned. (If the storage can't be
allocated, NULL is returned.)
*/
struct llnode *llnode_add(struct llnode *head, void *data)
{
struct llnode *new = malloc(sizeof *new);
if(new != NULL)
{
new->data = data;
new->next = head;
}
return new;
}
But this will only point to data. It won't know what kind of data it
points to, how big it is, how to process it, or anything like that. And
it won't "own" the data, so you have to do that, and you have to know
when to remove items from the list as and when they go out of scope
(and which items they are). This is a recipe for a million headaches.