cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : csetjmp (setjmp.h) : longjmp
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
csetjmp (setjmp.h)
jmp_buf
longjmp
setjmp

-

longjmp function
void longjmp (jmp_buf env, int val);
<setjmp>

Long jump

Restores the environment by the most recent invocation of the setjmp macro in the same invocation of the program. The information required to restore this environment is provided by parameter env, whose value is obtained from a previous call to setjmp.

The function never returns to the point where it has been invoked. Instead, the function transfers the control to the point where setjmp was used to fill the env parameter.

Parameters

env
Object of type jmp_buf containing information to restore the environment at the setjmp's calling point.
val
Value to which the setjmp expression evaluates.

Return value

None. The function never returns.

Example

/* longjmp example */
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>

main()
{
  jmp_buf env;
  int val;

  val=setjmp(env);

  printf ("val is %d\n",val);

  if (!val) longjmp(env, 1);

  return 0;
}

Output:

val is 0
val is 1

See also

setjmp Save calling environment for long jump (macro)
jmp_buf Type to hold information to restore calling environment (type)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us