makecontext 函数中的指针澄清
作为我作业的一部分,我一直在实现一个用户线程库。 我不明白 makecontext
函数:
makecontext(&(mainthread->threadctx),(void(*)(void))start_funct,1,args)
(void(*)(void))start_funct
到底是什么意思?为什么我必须这样写? 我不能把它写成
makecontext(&(mainthread->threadctx),start_funct,1,args) ?
请耐心等待,我还不太适应指针:)
I have been implementing a user threads library as part of my assignment.
I didn't understand the makecontext
function:
makecontext(&(mainthread->threadctx),(void(*)(void))start_funct,1,args)
What does (void(*)(void))start_funct
exactly mean? And why do I have to write it this way?
Can't I just write it as
makecontext(&(mainthread->threadctx),start_funct,1,args) ?
Please be patient with me, I am not yet comfortable with pointers :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
void(*)(void)
表示“指向不带参数并返回void
的函数的指针”。因此
(void(*)(void))start_funct
正在将start_funct
(我们可以假设是某种函数指针)` 转换为上述类型。 (有一个非常有用的在线工具 这可以帮助您,直到您更轻松地阅读声明)。你必须这样写,因为
start_funct
的签名不是void start_funct(void)
,所以需要强制转换。void(*)(void)
means "pointer to a function that takes no parameters and returnsvoid
".Therefore
(void(*)(void))start_funct
is castingstart_funct
(which we can assume is some kind of function pointer)` to the above type. (There is a very useful online tool that can help you with this until you get more comfortable reading declarations).You have to write it this way because the signature of
start_funct
is notvoid start_funct(void)
, so casting is required.