VxWorks Reference Manual : Libraries

ansiSetjmp

NAME

ansiSetjmp - ANSI setjmp documentation

ROUTINES

setjmp( ) - save the calling environment in a jmp_buf argument (ANSI)
longjmp( ) - perform non-local goto by restoring saved environment (ANSI)

DESCRIPTION

The header setjmp.h defines functions and one type for bypassing the normal function call and return discipline.

The type declared is:

jmp_buf
an array type suitable for holding the information needed to restore a calling environment.

The ANSI C standard does not specify whether setjmp( ) is a subroutine or a macro.

SEE ALSO

ansiSetjmp, American National Standard X3.159-1989


Libraries : Routines

setjmp( )

NAME

setjmp( ) - save the calling environment in a jmp_buf argument (ANSI)

SYNOPSIS

int setjmp
    (
    jmp_buf env
    )

DESCRIPTION

This routine saves the calling environment in env, in order to permit a longjmp( ) call to restore that environment (thus performing a non-local goto).

Constraints on Calling Environment

The setjmp( ) routine may only be used in the following contexts:

RETURNS

* From a direct invocation, setjmp( ) returns zero. From a call to longjmp( ), it returns a non-zero value specified as an argument to longjmp( ).

SEE ALSO

ansiSetjmp, longjmp( )


Libraries : Routines

longjmp( )

NAME

longjmp( ) - perform non-local goto by restoring saved environment (ANSI)

SYNOPSIS

void longjmp
    (
    jmp_buf env,
    int     val
    )

DESCRIPTION

This routine restores the environment saved by the most recent invocation of the setjmp( ) routine that used the same jmp_buf specified in the argument env. The restored environment includes the program counter, thus transferring control to the setjmp( ) caller.

If there was no corresponding setjmp( ) call, or if the function containing the corresponding setjmp( ) routine call has already returned, the behavior of longjmp( ) is unpredictable.

All accessible objects in memory retain their values as of the time longjmp( ) was called, with one exception: local objects on the C stack that are not declared volatile, and have been changed between the setjmp( ) invocation and the longjmp( ) call, have unpredictable values.

The longjmp( ) function executes correctly in contexts of signal handlers and any of their associated functions (but not from interrupt handlers).

WARNING

Do not use longjmp( ) or setjmp( ) from an ISR.

RETURNS

This routine does not return to its caller. Instead, it causes setjmp( ) to return val, unless val is 0; in that case setjmp( ) returns 1.

SEE ALSO

ansiSetjmp, setjmp( )