I am tinkering with setjmp
and longjmp
, implementing a simple try/catch exception system with them. setjmp
will return the integer 0
upon first calling it, and returns any other value you pass in into the call to longjump
otherwise.
However, according to this resource, which I presume is based on the C99 standard it actually is not allowed (in strict C99) to read out the result of setjmp
and store it in a variable.
Because of this, as well as because we might want to pass data that is different (e.g. larger than) an integer between longjmp
and setjmp
, I am looking to alternatives to pass data (an integer or a (pointer to a) struct) back up.
How can we do that (while keeping standads-compliant, i.e. not threading in 'undefined behaviour' territory)?