I am working on a school assignment in which I need to build a thread library.
I need pc to hold the address of the given Thread object's run() function.
When I try to cast a member function pointer to address_t (which is really unsigned long int) I get this error
../main.cpp: In function ‘void setup(Thread&)’:
../main.cpp:77:22: error: invalid cast from type ‘int (Thread::*)()’ to type ‘address_t {aka unsigned int}’
make: * [main.o] Error 1
Here's the function where I get the error:
void setup(Thread &thread)
{
address_t sp, pc;
sp = (address_t)stack1 + STACK_SIZE - sizeof(address_t);
int (Thread::*temp)() = &Thread::run;
pc = (address_t) temp; // @@ LINE 77 @@
sigsetjmp(jbuf[0],1);
(jbuf[0]->__jmpbuf)[JB_SP] = translate_address(sp);
(jbuf[0]->__jmpbuf)[JB_PC] = translate_address(pc);
sigemptyset(&jbuf[0]->__saved_mask);
}
A few clarification:
Thread is a class I wrote, currently doing nothing. It as a int run(void) as its "main" function. address_t, as I said, is typedef unsigned long int
Any ideas as to why I get this error? thanks