C++中abort和exit的区别

更新时间:2023-05-23 09:03:33 阅读: 评论:0

C++中abort和exit的区别
abort会发送SIGABORT信号
调⽤exit后,程序会调⽤静态对象和全局对象的析构函数,但abor什么析构函数都不会调⽤。
程序完全退出时,系统会释放所有未释放的内存和和其他资源
abort nds a SIGABRT signal, exit just clos the application performing normal cleanup.
You can handle an abort signal however you want, but the default behavior is to clo the application as well with an error code.
abort will not perform object destruction of your static and global members, but exit will.2017年2月16日
Of cour though when the application is completely clod the operating system will free up any unfreed memory and other resources.
In both abort and exit program termination (assuming you didn't override the default behavior), the return code will be returned to the parent process that started your application.
See the following example:
SomeClassType someobject;
void myProgramIsTerminating1(void)
{
cout<<"exit function 1"<<endl;
aston
}小学四年级英语课件
void myProgramIsTerminating2(void)
南昌会计{
cout<<"exit function 2"<<endl;
}
int main(int argc, char**argv)
{
stand upatexit (myProgramIsTerminating1);qw
atexit (myProgramIsTerminating2);
//abort();
return0;
英语三级成绩查询}
Comments:
If abort is uncommented: nothing is printed and the destructor of someobject will not be called.
package是什么意思If abort is commented like above: someobject destructor will be called you will get the following output:
sangexit function 2
exit function 1
工业机器人教育

本文发布于:2023-05-23 09:03:33,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/743191.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:对象   释放   全局   函数   静态   机器人   发送   课件
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图