Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - longjmp http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   longjmp

   Usage
   #include <setjmp.h>
   void longjmp(jmp_buf env, int value);

   int setjmp(jmp_buf env);

   Description
   These  functions  allow a goto between functions. They  are  good  for
   dealing with errors or interrupts encountered in low-level subroutines
   of a program.

   setjmp  saves the stack environment in the variable env for later  use
   by longjmp.

   longjmp restores the environment previously saved by setjmp in jmp_buf
   and is pointed to by envp. The return value is that of setjmp.

   NOTE: The environment must have been previously saved using setjmp  by
   a function that is currently active, and which is the same function or
   a parent of the function containing the call to longjmp.

   After  completion of longjmp, program execution continues just  as  if
   the  corresponding  call to setjmp had just returned with  value.  The
   value  will never be 0. If value is passed as 0, the value 1  will  be
   returned.

   Return Value
   setjmp returns a 0. There is no return value for longjmp.

   Example
   #include <setjmp.h>
   #include <stdio.h>

   void doscall(void);
   jmp_buf environment;
   int error_val = -1;

   main()
   {
   int error_code;
   error_code = setjmp(environment);
        if(error_code != 0)
        {
             printf("Longjmp called\n");
             exit(1);
        }
        printf("Setjmp called\n");
        docall();
   }

   docall()
   {
        longjmp(environment,error_val);
   }


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson