Rudra Dutta CSC 230 - Spring 2007, Section 001 Longjumps Rudra Dutta CSC 230 - Spring 2007, Section 001
“Long” jumps Violates function call-return discipline “Jump” is on stack, not source code Provided by the standard library Include <setjmp.h> Mark a place in the executing code where to come back (irrespective of current function call nesting) under certain circumstances Sometimes used for recovering from serious errors Copyright Rudra Dutta, NCSU, Spring, 2007
Longjump on the Stack Mark a place in the execution where to jump to Use setjmp to mark Pointer to current top of stack is saved At a future time, from inside a nested function call, can jump straight to this place in the stack Use longjmp Nested functions do not return (retroactively converted to “were not called”) MUST be nested (original function must still be on stack) Copyright Rudra Dutta, NCSU, Spring, 2007