Reputation: 9793
I've come across this piece of code in my O.S book:
void *foo()
{
// does something
pthread_exit(NULL);
}
What is the meaning of void *foo
?
Does that mean the function return a pointer to something of type void
?
Upvotes: 0
Views: 747
Reputation: 726579
No, it means that the function returns an pointer of the untyped type - void*
.
This is a "generic" pointer type. Any pointer to data can be cast to void*
, and returned back to the caller. However, in order to dereference the pointer, you must cast it to a non-void pointer type (int*
, long*
, char*
, and so on).
Upvotes: 3
Reputation: 53881
void *
means it returns a pointer to some type, it isn't specified which. In order to be used the pointer is casted to the appropriate type and then used. The fact that void *foo
is just a matter of spacing.
Check out this explanation
Upvotes: 2