?? setjmp.3
字號:
.TH setjmp 3 RISC.SH Namesetjmp, longjmp \- non-local goto.SH Syntax.nf.B #include <setjmp.h>.PP.B int setjmp (env).B jmp_buf env;.PP.B void longjmp (env, val).B jmp_buf env;.B int val;.SH DescriptionThe.PN setjmpand .PN longjmpfunctions help deal with errors and interrupts encountered in a low-level subroutine of a program..PPThe.PN setjmpfunction saves its stack environment in.I env(whose type,.IR jmp_buf ,is defined in the.I <setjmp.h>header file) for later use by.PN longjmp .It returns the value 0..PPThe.PN longjmpfunction restores the environment saved by the last call of.PN setjmpwith the corresponding.I envargument.After.PN longjmpfinishes, program executioncontinues as if the corresponding call of .PN setjmp(which must not itself have returned in the interim)had just returned the value.IR val.The.PN longjmpfunction cannot cause.PN setjmpto return the value 0. If.PN longjmpis invoked with a second argument of 0,.PN setjmpreturns 1.At the time of the second return from.PN setjmp ,all accessible data have values as of the time .PN longjmpis called.However, global variables have the expected values.For example, those as of the time ofthe .PN longjmp (see example)..SH Examples.EX#include <setjmp.h>jmp_buf env;int i = 0;main (){ void exit(); if(setjmp(env) != 0) { (void) printf("value of i on 2nd return from setjmp: %d\n", i); exit(0); } (void) printf("value of i on 1st return from setjmp: %d\n", i); i = 1; g(); /*NOTREACHED*/}g(){ longjmp(env, 1); /*NOTREACHED*/}.EE.PPIf the a.out resulting from this C language code is run, the output is as follows:.EXvalue of i on 1st return from setjmp:\^0 value of i on 2nd return from setjmp:\^1 .EE.NTUnexpected behavior occurs if.PN longjmp is called without a previous call to.PN setjmp ,or when the last such call was in a function which has since returned..NE.SH RestrictionsThe values of the registers on the second return from .PN setjmpare register values at the time of the first call to .PN setjmp, not those of the.PN longjmp .Thus, variables in a given function can produce unexpected resultsin the presence of.PN setjmp ,depending on whether they are register or stack variables..SH See Alsosignal(2).
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -