Reputation: 619
I am learning C. I need to define a function to type cast the value of void *
to the desired type. I'm not sure if I fully understand what I need to do. Here is my attempt. Can someone take a look and let me know if it's correct? If not, how should I fix it? Thank you in advance for your time.
void print_type(TYPE a)
{
void *v_ptr;
v_ptr = &a;
}
Upvotes: 0
Views: 468
Reputation:
In C, void *
is implicitly compatible with any data pointer type. If you have a POSIX implementation, then it's compatible with function pointers as well. There's no need for typecasting; conversely, it's even considered harmful.
Upvotes: 5