
在这个部分,我们将看到C语言中的setjump和longjump是什么。setjump()和longjump()位于setjmp.h库中。这两个函数的语法如下所示。
setjump(jmp_buf buf) : uses buf to store current position and returns 0. longjump(jmp_buf buf, i) : Go back to place pointed by buf and return i.
These are used in C for exception handling. The setjump() can be used as try block, and longjump() can be used as throw statement. The longjump() transfers control the pointe which is pointed by setjump().
这本书给出了一份关于python这门优美语言的精要的参考。作者通过一个完整而清晰的入门指引将你带入python的乐园,随后在语法、类型和对象、运算符与表达式、控制流函数与函数编程、类及面向对象编程、模块和包、输入输出、执行环境等多方面给出了详尽的讲解。如果你想加入 python的世界,David M beazley的这本书可不要错过哦。 (封面是最新英文版的,中文版貌似只译到第二版)
Here we will see how to print a number 100 times without using recursion, loop, or macro expansion. Here we will use the setjump() and longjump() functions to do that.
Example
#include#include jmp_buf buf; main() { int x = 1; setjmp(buf); //set the jump position using buf printf("5"); // Prints a number x++; if (x <= 100) longjmp(buf, 1); // Jump to the point located by setjmp }
输出
5555555555555555555555555555555555555555555555555555555555555555555555555555 555555555555555555555555










