atexit 函数的目的是什么? [英] what is the purpose of atexit function?
问题描述
我知道什么时候把函数的地址传给atexit
函数,
函数被执行.
I know when the address of the function is passed to atexit
function,
the function is excuted.
#include <stdlib.h>
int atexit(void (*func) void));
但是,使用atexit
函数的目的是什么?
However, what is the purpose of using atexit
function?
口头意义本身退出"是否与atexit
函数有关?
Does verbal meaning itself 'exit' relate to atexit
function?
推荐答案
atexit
将用于一些您希望在应用程序终止时执行的代码,而不管它从何处退出.一个例子是应用程序范围的记录器.您将调用 atexit(flush_log)
,因此当应用程序退出时,日志将被刷新,而无需开发人员记住刷新它.
atexit
would be used for some code that you want to execute when the application terminates, regardless of where it was exited from. One example would be an application-wide logger. You would call atexit(flush_log)
, so when the application exits, the log will be flushed, without the developer having to remember to flush it.
这篇关于atexit 函数的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!