简体   繁体   English

我应该如何键入cast void *?

[英]How should I type cast void *?

I am learning C. I need to define a function to type cast the value of void * to the desired type. 我正在学习C。我需要定义一个函数来将void *的值void *类型转换为所需的类型。 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;

}

In C, void * is implicitly compatible with any data pointer type. 在C中, void *与任何数据指针类型隐式兼容。 If you have a POSIX implementation, then it's compatible with function pointers as well. 如果您有POSIX实现,那么它也与函数指针兼容。 There's no need for typecasting; 不需要类型转换。 conversely, it's even considered harmful . 相反, 它甚至被认为是有害的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM