C ++:安全使用longjmp和setjmp? [英] C++: Safe to use longjmp and setjmp?
问题描述
在linux / gcc上的C ++中使用longjmp和setjmp可以安全地使用下面的语句?
- 异常处理我不知道longjmp / setjmp会对标准异常处理产生什么副作用)
-
* this
指针 - 信号
- 智能指针(boost的共享和入侵指针)
- 可以想到。
setjmp()
/ longjmp()
完全颠覆堆栈展开,因此异常处理以及RAII(一般为析构函数) p>
从18.7 / 4标准中的其他运行时支持:
自动对象将被抛出的异常转移
控制到程序中的另一个(目标)点,然后调用longjmp(jbuf,val)
因此,底线是 setjmp()
/ longjmp()
在C ++中不能播放。
Is it safe to use longjmp and setjmp in C++ on linux/gcc with regards to the following?
- Exception handling (I'm not implementing exception handling using longjmp/setjmp. I want to know what side effects longjmp/setjmp will have on standard exception handling)
*this
pointer- Signals
- Smart pointers (boost's shared and intrusive pointers)
- Anything else you can think of.
setjmp()
/longjmp()
completely subvert stack unwinding and therefore exception handling as well as RAII (destructors in general).
From 18.7/4 "Other runtime support" in the standard:
If any automatic objects would be destroyed by a thrown exception transferring control to another (destination) point in the program, then a call to
longjmp(jbuf, val)
at the throw point that transfers control to the same (destination) point has undefined behavior.
So the bottom line is that setjmp()
/longjmp()
do not play well in C++.
这篇关于C ++:安全使用longjmp和setjmp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!