Allen J
Allen J

Reputation: 23

C Function Pointer void value issue

I've been working on an assignment for an operating systems class (so please, only tips, no full answers), and one function whose parameters and return types were provided by my instructor but who's content was filled by me is throwing an error. The function is as follows:

void start_thread(void (*function)(void))
{
    TCB_t* stackPointer = malloc(8192); //8192 is a provided value for assignment
    TCB_t tcb;
    tcb = init_TCB(&tcb, function, stack, sizeof(stack));
    AddQueue(RunQ, tcb);
}

The following function is from the line the error is thrown on, this function was defined for the assignment and should not be changed.

void init_TCB (TCB_t *tcb, void *function, void *stackP, int stack_size)
{
     memset(tcb, '\0', sizeof(TCB_t));
     getcontext(&tcb->context);
     tcb->context.uc_stack.ss_sp = stackP;
     tcb->context.uc_stack.ss_size = stack_size;
     makecontext(&tcb->context, function, 0);
}

I am unfamiliar with C and especially the idea of function pointers, but all of my research says this code should not be throwing errors, but it is continually throwing the following:

error: void value not ignored as it ought to be

Upvotes: 1

Views: 230

Answers (1)

R Sahu
R Sahu

Reputation: 206607

tcb = init_TCB(&tcb, function, stack, sizeof(stack));

needs to be

init_TCB(&tcb, function, stackPointer, 8192);

I'll let you figure out why those changes make sense.

If they don't make sense, add a comment.

Upvotes: 2

Related Questions