gpt4 book ai didi

c++ - 为什么VC++引入非标准关键字: __leave?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:23:46 27 4
gpt4 key购买 nike

根据 MSDN :

The __leave statement is more efficient because it does not cause stack unwinding.

以我的理解,就是说:“这样一个普通的代码片段是危险的!”

struct A
{
int* p;

A() : p(new int) {}
~A() { delete p; }
};

void f()
{
__try
{
A a;
... // Doing somthing
if (the thing has gone bad) __leave;
... // Continue
}
__finally
{}
}

在 C++ 项目中完全避免 __leave 是最佳实践吗?

最佳答案

http://msdn.microsoft.com/en-us/library/yb3kz605.aspx

说:

For C++ programs, C++ exception handling should be used instead of structured exception handling. For more information, see Exception Handling in the C++ Language Reference.

编辑:此外,通常最好不要使用编译器特定的功能。

关于c++ - 为什么VC++引入非标准关键字: __leave?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18819205/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com