?
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
在頭文件<stdlib.h>中定義 | ||
---|---|---|
int atexit(void(* func)(void)); |
注冊(cè)func指向的函數(shù),在正常程序終止時(shí)(通過exit()或從main()返回)調(diào)用。 這些函數(shù)將按照它們注冊(cè)的相反順序調(diào)用,即最后注冊(cè)的函數(shù)將首先執(zhí)行。
相同的功能可以被多次注冊(cè)。
atexit
是線程安全的:從多個(gè)線程調(diào)用函數(shù)不會(huì)導(dǎo)致數(shù)據(jù)競(jìng)爭(zhēng)。
該實(shí)現(xiàn)保證支持至少32個(gè)函數(shù)的注冊(cè)。 確切的限制是實(shí)現(xiàn)定義的。
功能 | - | 指向正常程序終止時(shí)要調(diào)用的函數(shù)的指針 |
---|
如果注冊(cè)成功,則返回0
,否則為非零值。
#include <stdlib.h>#include <stdio.h> void f1(void){ puts("pushed first");} void f2(void){ puts("pushed second");} int main(void){ atexit(f1); atexit(f2);}
輸出:
pushed second pushed first
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.22.4.2 atexit函數(shù)(p:350)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.20.4.2 atexit函數(shù)(p:315)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.10.4.2 atexit函數(shù)
at_quick_exit(C11) | 注冊(cè)要在quick_exit調(diào)用(函數(shù))上調(diào)用的函數(shù) |
---|
| 用于atexit的C ++文檔 |