std::longjmp
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <csetjmp> 中定义
|
||
void longjmp( std::jmp_buf env, int status ); |
||
加载的执行上下文
env
保存以前调用setjmp的。这个函数不返回。控制权转移到宏观setjmp成立env
的调用点。这setjmp然后返回值,通过为status
.原文:
Loads the execution context
env
saved by a previous call to setjmp. This function does not return. Control is transferred to the call site of the macro setjmp that set up env
. That setjmp then returns the value, passed as the status
.如果是调用该函数setjmp已退出,其行为是不确定的(换句话说,只允许调用堆栈向上跳跃)
原文:
If the function that called setjmp has exited, the behavior is undefined (in other words, only long jumps up the call stack are allowed)
没有自动对象的析构函数被调用。如果更换的
std::longjmp
throw和setjmpcatch将执行一个不平凡的任何自动对象的析构函数,这样std::longjmp的行为是未定义的.原文:
No destructors for automatic objects are called. If replacing of
std::longjmp
with throw and setjmp with catch would execute a non-trivial destructor for any automatic object, the behavior of such std::longjmp is undefined.目录 |
[编辑] 参数
env | - | 变量std::setjmp保存的程序执行状态
原文: variable referring to the execution state of the program saved by std::setjmp |
status | - | 返回的值setjmp。如果它是等于0,1代替
原文: the value to return from setjmp. If it is equal to 0, 1 is used instead |
[编辑] 返回值
(无)
[编辑] 示例
#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 longjmp
|