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 🙂
void(*)(void)means “pointer to a function that takes no parameters and returnsvoid“.Therefore
(void(*)(void))start_functis 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_functis notvoid start_funct(void), so casting is required.