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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!