Chapter Contents

Previous

Next
longjmp

longjmp



Perform Nonlocal goto

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
ERRORS
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <setjmp.h>

void longjmp(jmp_buf env, int code);


DESCRIPTION

longjmp returns control to an ancestor routine, passing the value of the integer code . The point of return is determined by the contents of env , which should be initialized by a call to setjmp in the target routine. Note that if the value of code is 0, the value returned to the target is 1.

Seeblkjmp for more information on saving the signal mask as a part of a setjmp operation and restoring it as part of a longjmp operation. Also see blkjmp for more information on executing functions in ARMODE.


RETURN VALUE

Control does not return from longjmp .


CAUTION

longjmp does not change the program's signal mask. Use sigsetjmp to save the signal mask, and siglongjmp to restore the signal mask to the mask in effect when sigsetjmp was called.


ERRORS

If the target is not valid (that is, if the routine that called setjmp has terminated), a user ABEND 1204 is issued. If an invalid env is not detected, serious (and unpredictable) problems occur.

If you attempt to terminate a routine in a language other than C, a user ABEND 1224 is issued. See Appendix 6, "Using the indep Option for Interlanguage Communication," in the SAS/C Compiler and Library User's Guide for more information.


EXAMPLE

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

jmp_buf env;

main()
{
   int ret;

   if ((ret = setjmp(env)) != 0) {
      fprintf(stderr, "longjmp called with value %d\n", ret);
      exit(1);
   }
   dummy();
   fprintf(stderr, "longjmp was not called.\n");
}

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


RELATED FUNCTIONS

blkjmp , setjmp , siglongjmp


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.