Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list!
Read the UNIX man pages for setjmp() and longjmp(). Note that the intended purpose of these routines is for exception handling. C or C++ program can use setjmp to remember the context of the outer loop of the program, and whenever a computation in an inner part of the program detects an error, perhaps in a function called by a function called by a function, a call to longjmp() will escape to the saved context.
The steriotypical implementation of C (and Pascal, and Algol, and all related languages) stores all variables in memory at all times, using a single stack for both activation records and temporary variables. The CPU needed to execute a program in this model has only 3 registers, FP, the frame pointer, pointing to the base of the current activation record, SP, the stack pointer, pointing to the top of the stack, and PC, the program counter, pointing to the next instruction. Of course, real implementations are far more comples.
The Problem: Consider the following implementation of the jump buffer:
struct jumpbuffer { long int pc; /* the saved program counter */ long int sp; /* the saved stack pointer */ }What assumptions must be true of the code generated by the compiler to make this definition adequate?