转换为函数指针 [英] Cast to function pointer

查看:102
本文介绍了转换为函数指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了下面显示的代码行.

I have come across the line of code shown below.

我认为这可能是转换为返回void并采用void指针的函数指针.正确吗?

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*);

我也有编码约定,以rout_t结尾的类型就是函数签名的类型.您可以使用其他名称,因为_t是后缀保留通过 POSIX .

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.

稍后我在投射,也许可以这样称呼

Later on I am casting, perhaps to call it like

 ((sigrout_t*) SGENT_1_calc) (someptr);

这篇关于转换为函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆