digitalmars.com                      
Last update Sun Mar 4 12:00:59 2018

setjmp.h


longjmp

Header
setjmp.h
Prototype
void longjmp(jmp_buf env, int value);
Description
The longjmp function allows a goto between functions. It is good for dealing with errors or interrupts encountered in low-level subroutines of a program. longjmp restores the environment previously saved by setjmp in a jmp_buf pointed to by envp. The return value is that of setjmp. The environment must have been previously saved using setjmp by a function that is currently active, and which is the same function or a parent of the function containing the call to longjmp. After completion of longjmp, program execution continues just as if the corresponding call to setjmp had just returned with value. The value will never be 0. If value is passed as 0, the value 1 will be returned.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
setjmp
Example
/* Example for longjmp, setjmp */ 
#include <setjmp.h> 
#include <stdio.h>
#include <stdlib.h>

jmp_buf environment; 
int error_val = -1; 

void docall(void) {   
 longjmp(environment, error_val); 
} 
void main() {   
 int error_code; 

 error_code = setjmp(environment); 
 if (error_code != 0) {   
    printf("Longjmp called\n"); 
    exit(EXIT_FAILURE); 
 } 
 printf("Setjmp called\n"); 
 docall(); 
} 
Output
Setjmp called
Longjmp called 

setjmp

Header
setjmp.h
Prototype
int setjmp(jmp_buf env);
Description
Coupled with longjmp, setjmp allows a "goto" between functions. Jumps are good for dealing with errors or interrupts encountered in low-level subroutines of a program.
Synonym
Function: _setjmp
Return Value
setjmp returns a 0 when it is called to save the environment for a subsequent longjmp call; its value is that of the longjmp argument. If the longjmp argument is 0, it is changed to 1.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
longjmp
Home | Compiler & Tools | IDDE Reference | STL | Search | Download | Forums