0

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;

}
Matteo
  • 14,696
  • 9
  • 68
  • 106
user2203774
  • 609
  • 4
  • 13
  • 25

1 Answers1

5

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.

Community
  • 1
  • 1
  • 1
    +1. I was also thinking about «value of void * to the desired type»... Not sure if just a bad description of a question about converting a pointer to `uintptr_t` or something like that :-> –  May 08 '13 at 20:15
  • @VladLazarenko Thanks. Well, if I understood the question well, then this is all what OP is looking for... –  May 08 '13 at 20:16