foobar

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  6 随笔 :: 14 文章 :: 0 评论 :: 0 Trackbacks
int atexit ( void ( * function ) (void) );               <cstdlib>

 The function pointed by the function pointer argument is called when the program terminates normally.

If more than one atexit function has been specified by different calls to this function, they are all executed in reverse order as a stack, i.e. the last function specified is the first to be executed at exit.

One single function can be registered to be executed at exit more than once.

C++ implementations are required to support the registration of at least 32 atexit functions.

Parameters

function
Function to be called. The function has to return no value and accept no arguments.

Return Value

A zero value is returned if the function was successfully registered, or a non-zero value if it failed.

Example

/* atexit example */
            #include <stdio.h>
            #include <stdlib.h>
            void fnExit1 (void)
            {
            puts ("Exit function 1.");
            }
            void fnExit2 (void)
            {
            puts ("Exit function 2.");
            }
            int main ()
            {
            atexit (fnExit1);
            atexit (fnExit2);
            puts ("Main function.");
            return 0;
            }
            

Output:

            Main function.
Exit function 2.
Exit function 1.

posted on 2007-11-15 23:47 foobar 阅读(441) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理