Question
Complete the program below. Write the code for the two functions setjmp() and longjmp(). The code will provide smaller functionality than the C library version
Complete the program below. Write the code for the two functions setjmp() and longjmp(). The code will provide smaller functionality than the C library version and will simply work correctly in the program shown below. The only requirement is that when main () calls fun1() and fun1() calls fun2(), if fun2() calls longjmp() as it does in the example below then fun2() does not return to fun1() but instead setjmp() returns to main() with return value equal to 1.
main () { int r; r = setjmp(r); if (r == 0) { fun1(); return(0); } else { print_str("error "); return(2); } } setjmp (v) int v; { /* ..... */ return(0); } longjmp (v) int v; { /* ..... */ return(1); } fun1 () { print_str("start fun1 "); fun2(); return(0); } fun2 () { print_str("start fun2 "); longjmp(data); return(0); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started