coblongjmp

With the cobsetjmp function, provides the capability of a non-local GO TO, for use in error or exception handling.
Restriction:

This function is supported for native COBOL only.

Syntax:

#include "cobsetjmp.h"

void coblongjmp(struct cobjmp_buf *buf);

Parameters:

buf A buffer in which the current execution environment is saved.

Comments:

The cobsetjmp() function saves the environment of the current COBOL program and C function in the buffer pointed to by buf. It calls the C library function setjmp(), which immediately returns a value of 0.

A subsequent call to coblongjmp() either from elsewhere in the C function that called cobsetjmp(), or from one of its C or COBOL subprograms, causes execution to be resumed at the point immediately after the call to cobsetjmp().

After calling coblongjmp(), cobsetjmp() returns a non-zero value, thus enabling the value to be tested after the cobsetjmp() call.

The following restrictions apply when using the coblongjmp() and cobsetjmp() functions:

  • cobsetjmp() and coblongjmp can be called from a C program only; they cannot be called from COBOL.
  • coblongjmp() must be called from the same or from a lower level in the CALL/PERFORM hierarchy of control flow as cobsetjmp(). In the intervening time, control must not have been returned to a higher level. Specifically, control must not have been returned from the C function that called cobsetjmp().
  • If coblongjmp() returns control to a different call level than that used by cobsetjmp(), programs exited by this mechanism appear to have been exited normally and can be called again later in the program's run.
  • coblongjmp cannot be used if a CHAIN has been made since cobsetjmp was last called.
  • coblongjmp() cannot be used in an error procedure, exit procedure or signal handler.

Equivalent COBOL Syntax:

None.

Example:

The following shows how to use the coblongjmp() and cobsetjmp() functions:

void
some_c_func(void)
{
    struct cobjmp_buf buf;

    if (cobsetjmp(&buf) != 0)
    {
        cobprintf("Returned from coblongjmp\n");
        return;
    }
  
    /* Valid code here - for example can call COBOL */

    coblongjmp(&cobjmp_buf);
}