onjmp -- Define Target for Nonlocal goto

SYNOPSIS

 #include <lcjmp.h>

 void onjmp(jmp_buf env, int code, target);
 

DESCRIPTION

onjmp defines the target label as a point to which control should be transferred by a call to longjmp. The longjmp call specifies the same env value as onjmp. The integer value specified by the longjmp call is stored in the code integer.

onjmp sets the code variable to 0 on completion. Because the occurrence of a longjmp assigns onjmp a value other than 0, the value of code can be tested elsewhere to determine whether a jump has taken place.

RETURN VALUE

onjmp has no return value.

CAUTION

Variables of storage class auto and register, whose values are changed between the onjmp and longjmp calls, have indeterminate values after the branch to target unless declared volatile.

onjmp is implemented as a macro and should not be used in any position where a value is required.

PORTABILITY

onjmp is not a Standard construct; however, the macro that implements it is portable to any system that implements setjmp.

IMPLEMENTATION

onjmp is implemented as
 #define onjmp(e, c, t) if (c = setjmp(e)) goto t
 
See setjmp for further implementation information.

EXAMPLE

  #include <stdio.h>
  #include <lcjmp.h>
  #include <stdlib.h>

  jmp_buf env;
  void dummy();

  main()
  {
     int errcode;

        /* Allow restart via longjmp. */
     onjmp(env, errcode,cleanup);
     dummy();
     puts("No error occurred in dummy routine.");
     return;
     cleanup:
     printf("Beginning cleanup for error number %dn", errcode);
  }

  void dummy()
  {
     puts("Entering dummy routine.");
     longjmp(env, 3);
     puts("Never reached.");
  }

 

RELATED FUNCTIONS

longjmp, setjmp

SEE ALSO

Program Control Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.