Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <setjmp.h>
    int setjmp( jmp_buf env );

Description:
    The setjmp function saves its calling environment in its  jmp_buf
    argument, for subsequent use by the  longjmp function.

    In some cases, error handling can be implemented by using setjmp to
    record the point to which a return will occur following an error.  When
    an error is detected in a called function, that function uses  longjmp
    to jump back to the recorded position.  The original function which
    called setjmp must still be active (it cannot have returned to the
    function which called it).

    Special care must be exercised to ensure that any side effects that are
    left undone (allocated memory, opened files, etc.) are satisfactorily
    handled.

Returns:
    The setjmp function returns zero when it is initially called.  The
    return value will be non-zero if the return is the result of a call to
    the  longjmp function.  An if statement is often used to handle these
    two returns.  When the return value is zero, the initial call to setjmp
    has been made; when the return value is non-zero, a return from a
     longjmp has just occurred.

See Also:
    longjmp

Example:
    /* show LONGJMP, SETJMP */

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

    jmp_buf env;

    void main()
      {
        int ret_val;

        ret_val = 293;
        if( 0 == ( ret_val = setjmp( env ) ) ) {
          printf( "after setjmp %d\n", ret_val );
          rtn();
          printf( "back from rtn %d\n", ret_val );
        } else {
          printf( "back from longjmp %d\n", ret_val );
        }
      }

    rtn()
      {
        printf( "about to longjmp\n" );
        longjmp( env, 14 );
      }

    produces the following:

    after setjmp 0
    about to longjmp
    back from longjmp 14

Classification:
    ANSI

Systems:
    MACRO

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