Search code examples
cc99setjmpstatic-memory-allocation

What is stack reallocation and when does it happen?


It is stated that you stack reallocation can happen. I don't understand this. I thought the whole point of setjmp/longjmp was to save the stack, and that it would be valid when longjmp'ing back. The comment seems to suggest the whole stack could be moved. This would offset all pointers, so I see why it should be avoided. But when does stack reallocation happen? I never heard this term before.


Solution

  • It seems that comment about stack reallocation only applies to a coro stack, and not the general C stack

    One would not generally pass the general C stack to a function, only an implementation of your own as follows:

     /*
      * Create a new coroutine from the given function, and with the
      * given stack.
      */
     EXPORT
     extern coro coro_new(_entry fn);
    

    So, setjmp/longjmp would be as safe to use as always.