共用方式為


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 對等用法

System::Diagnostics::Process::Exited

請參閱

參考

流程控制和環境控制

abort

exit、_exit

_onexit、_onexit_m