0

I am trying to call longjmp. Setjmp works, but longjmp gives me a type error.

void thread_start_threading(void)
{
    setjmp(env);
    dispatch();
    current_thread->function(current_thread->arg);
}

And then later:

void thread_yield(void)
{
    longjmp(env, 9); 
    return;
}

The error it gives me is warning: passing argument 1 of ‘longjmp’ makes pointer from integer without a cast

What I really want is to save the state of the registers and then restore them later. I don't think i need to use the argument to do that. But I could be wrong. I don't grok setjmp.

EDIT: More code

Brandon
  • 3,573
  • 6
  • 19
  • 21
  • 3
    Is the `env` used in the `longjmp` the same as the `env` used in the `setjmp`? Could there be a different `env` in scope? Where is the `while` that goes with the `do`? – pat Feb 12 '14 at 05:12
  • There is only one env, and I just forgot to paste the while part. – Brandon Feb 12 '14 at 15:18
  • 1
    Run the source file through the C preprocessor (gcc -E) and see what the compiler is really compiling. – pat Feb 12 '14 at 15:33
  • 1
    Why are you passing `9` to `longjmp` when you are ignoring the return value of `setjmp`? – pat Feb 12 '14 at 15:35
  • I don't actually need that value for anything (at this iteration), but `longjmp` requires a second argument. – Brandon Feb 12 '14 at 18:16
  • @brandon: show more code – Jabberwocky Feb 13 '14 at 13:41
  • For whatever reason, the compiler thinks that `env` has an integer type instead of an array type (`jmp_buf` is required to be an array type of some sort by the C language standard). So double-check the declaration of `env` and make sure it's not being `#define`d by a macro somewhere. – Adam Rosenfield Feb 14 '14 at 03:59

0 Answers0