Chapter Contents

Previous

Next
setjmp

setjmp



Define Label for Nonlocal goto

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <setjmp.h>

int setjmp(jmp_buf env);


DESCRIPTION

setjmp defines a target for a nonlocal goto . The call to setjmp always returns 0. If another routine, called later by the caller of setjmp , issues the call longjmp(env, code) , the earlier call to setjmp is resumed. This time, setjmp returns the value contained in the code argument to longjmp .

See blkjmp 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

A true return from setjmp always produces a 0. When control returns from setjmp because longjmp was used, the return value is nonzero.


CAUTION

Variables of storage class auto and register , whose values have been changed between the setjmp and longjmp calls, have indeterminate values on return to setjmp unless declared volatile.


EXAMPLE

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

jmp_buf env;
void dummy();

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()
{
   puts("Entering dummy routine.");
   longjmp(env, 3);
   puts("Never reached.");
}


RELATED FUNCTIONS

longjmp , sigsetjmp


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

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