void pointer
- From: "Roman Mashak" <mrv@xxxxxxxx>
- Date: Fri, 22 Jun 2007 21:15:28 -0700
Hello,
I'm studying linked lists and implemented the following:
struct list_node
{
void *data;
struct list_node *next;
};
I intentionally defined 'void *' for data field in order to use various
types. Here is a function adding element to linked list:
/* add element in the beginning of list */
static list *list_add(list **p, void *data)
{
list *n = malloc(sizeof(list));
n->next = *p;
*p = n;
n->data = (void *)data;
return n;
}
My question is: is this valid type casting
n->data = (void *)data;
Will I be able to add 'data' of 'int', 'long', 'char' etc. types? Is this
right approach?
Thank you.
--
Best regards, Roman
.
- Follow-Ups:
- Re: void pointer
- From: Army1987
- Re: void pointer
- From: Stephen Sprunk
- Re: void pointer
- From: CBFalconer
- Re: void pointer
- From: Richard Tobin
- Re: void pointer
- From: Richard Heathfield
- Re: void pointer
- Prev by Date: Re: fscanf hangs
- Next by Date: Sequence point question
- Previous by thread: How widely supported is variable type 'long long int' ?
- Next by thread: Re: void pointer
- Index(es):
Relevant Pages
|