c语言提供了两个函数可以用来非local的跳转:
#include <setjmp.h>
int setjmp(jmp_buf envbuf );
void longjmp(jmp_buf env, int val);
setjmp保存当前的系统堆栈到envbuf中,第一次调用返回0,以后当我们调用longjmp
时返回longjmp设置的val,但是不可以返回0(val设置为0,返回1).
longjmp恢复前线程最近一次调用setjmp保存的环境,回到该setjmp处继续执行。
例子:
#include <setjmp.h>
#include <stdio.h>
jmp_buf ebuf;
void f(void);
int main(void){
int i;
printf("1");
i = setjmp(ebuf);
if(i == 0){
f();
printf("This will not be printed.");
}
printf("%d",i);
return 0;
}
void f(void){
printf("2");
longjmp(ebuf,3);
}
结果输出:123
分享到:
相关推荐
关于setjmp和longjmp的详细介绍,可以实现类似异常处理。等等,以及使用时注意事项,和goto的差别
用法直接从minibuffer调用它, M-x goto-line-preview或者,您可以将其全局绑定以替换goto-line : ( global-set-key [remap goto-line] 'goto-line-preview )贡献如果您想为该项目做出贡献,则可以克隆并向该存储库...
Atom-atom-goto-definition.zip,贬低转到定义,atom是一个用web技术构建的开源文本编辑器。
The C programming Language ...Non-local Jumps: <setjmp.h> Signals: <signal.h> Date and Time Functions: <time.h> Implementation-defined Limits: <limits.h> and <float.h> Appendix C: Summary of Changes
在C标准库中有一对非常有趣的函数setjmp()函数与longjmp()函数,用来实现代替goto 实现一些非常重要的功能,如异常处理。C语言中,标准库函数setjmp和longjmp形 成了结构化异常工具的基础。简单的说即setjmp实例化...
./2-goto-via-command-stack.js const s = useContinuation ( ) const { setGoto , setStop , state , push } = s . next ( [ false , false ] ) . value push ( "state.a = 3" ) s . next ( [ true , false ] ) /...
c 4) there are no irrecoverable convergence problems c if (konv .ne. 0) then write (iof1,*) ' Convergence problems of type ', konv close(iof1) stop else if (nit .ge. itmax) then write (iof1,*) '...
pip3 install goto-project --user # or pip if python3 is your default interpreter 您可以使用安装zsh完成 antigen bundle sivakov512/goto-project completions/zsh 现在输入gt ,然后按,您将看到所有可用的...
GOTO-20是Java Bytecode编译器的basicode-2。
python-goto-函式修饰符, 对 bytecode 进行重定向, Python 中的 goto
Extension for React项目可以打开当前打开的组件的... 运行命令goto-react: Open component/container 。 贡献 如果发现错误,请创建或 。 学分 用来演示用法的代码是一个来自 repo的。 执照 :copyright: rodrigobdz 。
goto在线解密工具,php源码,内含教程
t.goto(-97,180) t.goto(-97,189) t.goto(-94,193) t.goto(-89,204) t.goto(-84,213) t.goto(-76,223) t.goto(-73,226) t.goto(-70,226) t.goto(-69,222) t.goto(-78,208) t.goto(-83,198) t.goto(-89,184) ...
在C语言中,使用goto和标签的方式模拟try catch的功能,使用setjmp和longjmp方式模拟try catch的功能,两种方式都可以使用,setjmp的方式可以支持try catch嵌套,goto的方式不支持嵌套,但是jmpbuf的开销是比较大的...
资源来自pypi官网。 资源全名:goto_label-0.1.1-py3-none-any.whl
2.1 Priam and Everex Hard Disks 2.2 SyQuest Removable Hard Disk 2.3 Bernoulli Drive 2.4 Disk Manager 2.5 SpeedStor and Volume Expansion 2.6 Novell Partitions 2.7 Vfeature Deluxe 2.8 Columbia ...
语言:English 在github存储库中浏览初始提交的简单方法 将按钮添加到github存储库的提交历史页面中的初始提交中。 源代码:https://github.com/fqxufo/goto-intial-commits
计算机控制显微镜电动平移台移动到精确位置
goto-project-rs:在Shell中轻松快速地进行项目切换!