atexit

处理所指定的功能在退出。

int atexit(
   void (__cdecl *func )( void )
);

参数

  • func
    将调用的函数。

返回值

atexit 返回 0; 如果成功或非零值,如果错误。

备注

atexit 函数传递 (func) 的调用的地址功能,当程序通常时停止。 连续调用 atexit 创建前函数的寄存器, (LIFO)初始顺序。 函数传递给 atexit 不能采用参数。 atexit_onexit 使用堆保存功能注册。 因此,可以注册函数的数目取决于堆内存只限制。

atexit 功能的代码不应包含在可能已经卸载的任何 DLL 中的所有依赖项,当 atexit 函数调用时。

若要生成一个 ANSI 兼容应用程序,请使用 ANSI 标准 atexit 功能 (而不是类似的 _onexit 函数)。

要求

实例

必需的头

atexit

stdlib.h

示例

,当 atexit 调用时,此过程推送到要执行的堆栈的四个功能上。 在程序退出时,这些程序在最后执行,第一个基类型。

// crt_atexit.c
#include <stdlib.h>
#include <stdio.h>

void fn1( void ), fn2( void ), fn3( void ), fn4( void );

int main( void )
{
   atexit( fn1 );
   atexit( fn2 );
   atexit( fn3 );
   atexit( fn4 );
   printf( "This is executed first.\n" );
}

void fn1()
{
   printf( "next.\n" );
}

void fn2()
{
   printf( "executed " );
}

void fn3()
{
   printf( "is " );
}

void fn4()
{
   printf( "This " );
}
      

.NET Framework 等效项

系统:: 诊断:: 处理:: 退出

请参见

参考

处理和环境控件

abort

exit, _exit

_onexit, _onexit_m