调用exit()时,析构函数是否运行? [英] Are destructors run when calling exit()?

查看:299
本文介绍了调用exit()时,析构函数是否运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:






在C ++中,当应用程序调用exit(3)时,栈上的析构函数应该运行到unwind





























$ b b

基本上,当 exit 被调用时静态对象被销毁,执行 atexit 处理程序,刷新和关闭,并删除由 tmpfile 创建的文件。本地自动对象不会被销毁。



调用 abort 会让更少发生:无需清理。



干杯& hth。,


Possible Duplicate:
Will exit() or an exception prevent an end-of-scope destructor from being called?

In C++, when the application calls exit(3) are the destructors on the stack supposed to be run to unwind the stack?

解决方案

C++98 §18.3/8 discusses this.

Essentially, when exit is called static objects are destroyed, atexit handlers are executed, open C streams are flushed and closed, and files created by tmpfile are removed. Local automatic objects are not destroyed. I.e., no stack unwinding.

Calling abort lets even less happen: no cleanup whatsoever.

Cheers & hth.,

这篇关于调用exit()时,析构函数是否运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆