<bdo id='oWyes'></bdo><ul id='oWyes'></ul>
<i id='oWyes'><tr id='oWyes'><dt id='oWyes'><q id='oWyes'><span id='oWyes'><b id='oWyes'><form id='oWyes'><ins id='oWyes'></ins><ul id='oWyes'></ul><sub id='oWyes'></sub></form><legend id='oWyes'></legend><bdo id='oWyes'><pre id='oWyes'><center id='oWyes'></center></pre></bdo></b><th id='oWyes'></th></span></q></dt></tr></i><div id='oWyes'><tfoot id='oWyes'></tfoot><dl id='oWyes'><fieldset id='oWyes'></fieldset></dl></div>

      1. <legend id='oWyes'><style id='oWyes'><dir id='oWyes'><q id='oWyes'></q></dir></style></legend>
      2. <tfoot id='oWyes'></tfoot>

        <small id='oWyes'></small><noframes id='oWyes'>

      3. exit() 和 abort() 有什么区别?

        What is the difference between exit() and abort()?(exit() 和 abort() 有什么区别?)
          1. <small id='lMS7H'></small><noframes id='lMS7H'>

            <legend id='lMS7H'><style id='lMS7H'><dir id='lMS7H'><q id='lMS7H'></q></dir></style></legend>
              <bdo id='lMS7H'></bdo><ul id='lMS7H'></ul>

                  <tbody id='lMS7H'></tbody>
              • <i id='lMS7H'><tr id='lMS7H'><dt id='lMS7H'><q id='lMS7H'><span id='lMS7H'><b id='lMS7H'><form id='lMS7H'><ins id='lMS7H'></ins><ul id='lMS7H'></ul><sub id='lMS7H'></sub></form><legend id='lMS7H'></legend><bdo id='lMS7H'><pre id='lMS7H'><center id='lMS7H'></center></pre></bdo></b><th id='lMS7H'></th></span></q></dt></tr></i><div id='lMS7H'><tfoot id='lMS7H'></tfoot><dl id='lMS7H'><fieldset id='lMS7H'></fieldset></dl></div>

                1. <tfoot id='lMS7H'></tfoot>
                  本文介绍了exit() 和 abort() 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 C 和 C++ 中,exit()abort() 有什么区别?我试图在出现错误后结束我的程序(不是异常).

                  In C and C++, what is the difference between exit() and abort()? I am trying to end my program after an error (not an exception).

                  推荐答案

                  abort() 退出程序而不调用使用 注册的函数atexit() 首先,而不是先调用对象的析构函数.exit() 在退出您的程序之前执行这两项操作.但是它不会为自动对象调用析构函数.所以

                  abort() exits your program without calling functions registered using atexit() first, and without calling objects' destructors first. exit() does both before exiting your program. It does not call destructors for automatic objects though. So

                  A a;
                  void test() { 
                      static A b;
                      A c;
                      exit(0);
                  }
                  

                  会正确地析构ab,但不会调用c的析构函数.abort() 不会调用两个对象的析构函数.由于这是不幸的,C++ 标准描述了一种确保正确终止的替代机制:

                  Will destruct a and b properly, but will not call destructors of c. abort() wouldn't call destructors of neither objects. As this is unfortunate, the C++ Standard describes an alternative mechanism which ensures properly termination:

                  具有自动存储期的对象都在一个程序中销毁,该程序的函数main()不包含自动对象并执行对exit()的调用.通过抛出在 main() 中捕获的异常,可以将控制直接转移到这样的 main().

                  Objects with automatic storage duration are all destroyed in a program whose function main() contains no automatic objects and executes the call to exit(). Control can be transferred directly to such a main() by throwing an exception that is caught in main().

                  struct exit_exception { 
                     int c; 
                     exit_exception(int c):c(c) { } 
                  };
                  
                  int main() {
                      try {
                          // put all code in here
                      } catch(exit_exception& e) {
                          exit(e.c);
                      }
                  }
                  

                  不要调用exit(),而是安排代码throw exit_exception(exit_code);.

                  Instead of calling exit(), arrange that code throw exit_exception(exit_code); instead.

                  这篇关于exit() 和 abort() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                  <small id='WCxyz'></small><noframes id='WCxyz'>

                    <tfoot id='WCxyz'></tfoot>
                      <bdo id='WCxyz'></bdo><ul id='WCxyz'></ul>

                        <i id='WCxyz'><tr id='WCxyz'><dt id='WCxyz'><q id='WCxyz'><span id='WCxyz'><b id='WCxyz'><form id='WCxyz'><ins id='WCxyz'></ins><ul id='WCxyz'></ul><sub id='WCxyz'></sub></form><legend id='WCxyz'></legend><bdo id='WCxyz'><pre id='WCxyz'><center id='WCxyz'></center></pre></bdo></b><th id='WCxyz'></th></span></q></dt></tr></i><div id='WCxyz'><tfoot id='WCxyz'></tfoot><dl id='WCxyz'><fieldset id='WCxyz'></fieldset></dl></div>
                          <tbody id='WCxyz'></tbody>
                          1. <legend id='WCxyz'><style id='WCxyz'><dir id='WCxyz'><q id='WCxyz'></q></dir></style></legend>