加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

为什么VC引入了非标准关键字:__ leave?

发布时间:2020-12-16 09:47:28 所属栏目:百科 来源:网络整理
导读:根据 MSDN: The __leave statement is more efficient because it does not cause stack unwinding. 据我所知,就是说:“这样一个通用的代码片段是危险的
根据 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.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读