setjmp
来自cppreference.com
![]() |
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <csetjmp> 中定义
|
||
#define setjmp(env) /* implementation-defined */ |
||
env
类型std::jmp_buf到一个变量保存当前的执行上下文。这个变量可以在以后用来恢复当前的执行上下文std::longjmp功能。即,当呼叫std::longjmp功能,继续执行在特定呼叫站点构造std::jmp_buf变量传递到std::longjmp。在这种情况下,setjmp回报寿值传递给std::longjmp原文:
Saves the current execution context into a variable
env
of type std::jmp_buf. This variable can later be used to restore the current execution context by std::longjmp function. That is, when a call to std::longjmp function is made, the execution continues at the particular call site that constructed the std::jmp_buf variable passed to std::longjmp. In that case setjmp returns tho value passed to std::longjmp.目录 |
[编辑] 参数
env | - | 变量来保存程序的执行状态.
原文: variable to save the execution state of the program to. |
[编辑] 返回值
0如果宏被称为原代码的执行上下文被保存到
env
.原文:
0 if the macro was called by the original code and the execution context was saved to
env
.如果非本地跳转非零值。在相同的返回值传递给std::longjmp.
原文:
Non-zero value if a non-local jump was just performed. The return value in the same as passed to std::longjmp.
[编辑] 示例
#include <iostream> #include <csetjmp> std::jmp_buf jump_buffer; [[noreturn]] void a(int count) { std::cout << "a(" << count << ") called\n"; std::longjmp(jump_buffer, count+1); // setjump() will return count+1 } int main() { int count = setjmp(jump_buffer); if (count != 9) { a(count); // This will cause setjmp() to exit } }
输出:
a(0) called a(1) called a(2) called a(3) called a(4) called a(5) called a(6) called a(7) called a(8) called
[编辑] 另请参阅
跳转到指定的位置 (函数) | |
C documentation for setjmp
|