[应用相关] 在下面的代码中,atexit()并没有被调用,为什么?

[复制链接]
849|0
 楼主| OKAKAKO 发表于 2024-8-31 14:41 | 显示全部楼层 |阅读模式
ma, AI, 代码, TI, ID, TE


  1. #include<stdio.h>

  2. void func(void)
  3. {
  4.     printf("\n Cleanup function called \n");
  5.     return;
  6. }

  7. int main(void)
  8. {
  9.     int i = 0;

  10.     atexit(func);

  11.     for(;i<0xffffff;i++);

  12.     _exit(0);
  13. }


经过不断确认发现_exit()函数的使用,该函数并没有调用atexit()等函数清理。如果使用atexit()就应当使用exit()或者“return”与之相配合。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

260

主题

2096

帖子

4

粉丝
快速回复 在线客服 返回列表 返回顶部