铸造一个空指针结构 [英] Casting a void pointer to a struct
本文介绍了铸造一个空指针结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始感觉舒服℃,然后我跑进类型转换。如果我有以下的在* .h文件中定义的
结构数据{
int值;
字符*标签;
};
这在其他的* .h文件
#定义类型为void *
我怎么投的无效指针结构,这样我可以使用的传递到函数的变量TYPE VAL?例如,如果我想利用值TYPE VAL点,我怎么投它,这样我可以在价值传递给另一个功能是什么?
解决方案
(结构数据*)指针
会施放一个指向无效的指针结构数据
。
I started feeling comfortable with C and then I ran into type casting. If I have the following defined in an *.h file
struct data {
int value;
char *label;
};
and this in another *.h file
# define TYPE void*
How do I cast the void pointer to the struct so that I can use a variable "TYPE val" that's passed into functions? For example, if I want to utilize the value that TYPE val points to, how do I cast it so that I can pass that value to another functions?
解决方案
(struct data*)pointer
will cast a pointer to void to a pointer to struct data
.
这篇关于铸造一个空指针结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文