1

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

1
  • Did you write init_TCB? Conversions from function pointers to void pointers is not supported by C, formally it is undefined behavior. In reality it is a common non-standard extension though. If you didn't write it, tell your teacher that they shouldn't be teaching non-standard C. Commented Oct 30, 2015 at 7:45

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Okay awesome, thank you. I already see why the assignment wasn't working. I'll definitely have to look into that sizeof() change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.