How should I type cast void *?

亡梦爱人 提交于 2019-12-13 04:05:36

问题


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;

}

回答1:


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.



来源:https://stackoverflow.com/questions/16449206/how-should-i-type-cast-void

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!