铸造为一个函数指针? [英] Cast to function pointer?
本文介绍了铸造为一个函数指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所遇到如下所示的code线
我想这可能是一个投地返回void并接受一个空指针的函数指针,是正确的?
(无效(*)(无效*))SGENT_1_calc
解决方案
是的,这是正确的。我觉得这不是很可读的,所以我建议在声明函数的签名必须指出:
无效的typedef sigrout_t(无效*);
我也有编码约定的以 rout_t
结束的类型是这种类型的函数签名。否则你可能名字,因为 _t
为后缀的由Posix的保留
在我后面很铸造,也许叫它像
((sigrout_t *)SGENT_1_calc)(someptr);
Have come across the line of code shown below I think it may be a cast to a function pointer that returns void and takes a void pointer, is that correct?
(void (*)(void *))SGENT_1_calc
解决方案
Yes it is correct. I find that not very readable, so I suggest declaring the signature of the function to be pointed:
typedef void sigrout_t(void*);
I also have the coding convention that types ending with rout_t
are such types for functions signatures. You might name it otherwise, since _t
is a suffix reserved by Posix
latter on I am casting, perhaps to call it like
((sigrout_t*) SGENT_1_calc) (someptr);
这篇关于铸造为一个函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文