This blog is under construction

Saturday, 5 May 2012

setjmp, longjmp

Header file:
     setjmp.h

Synopsis:
     int setjmp(jmp_buf env);
     void longjmp(jmp_buf env, int val);

Description:
 setjmp It saves the stack environment in  env for use by longjmp.  And the stack environment gets invalidated if the function calling setjmp returns.
 longjmp It restores the state saved by the most recent call of setjmp or it makes our program execution shift to the last call of setjmp.





Sample program for setjmp and longjmp:



  #include<stdio.h>
  #include<setjmp.h>
  int main() {
        jmp_buf env;
        int flag = 0;
        if(setjmp(env) == 0) {
                printf("setjmp called directly\n");
        } else {
                printf("Hit due to the call of longjmp\n");
                flag = 1;
        }
        if(!flag)
                longjmp(env,4);
        printf("End of code\n");
        return 0;
  }





  Output:
  jp@jp-VirtualBox:~/cpgms/setjmp$ ./a.out
  setjmp called directly
  Hit due to the call of longjmp
  End of code




1 comment:

  1. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.

    Data Science Interview Questions

    Angular JS Interview Questions

    Big Data Training in Velachery

    AWS Certified Developer

    Best Resource of Learning Devops

    Blueprism Interview Questions

    Automation Anywhere Interview Questions

    ReplyDelete