aatteexxiitt() -- General Function (libc)

Register a function to be called when the program exits
#iinncclluuddee <ssttddlliibb.hh>
iinntt aatteexxiitt(vvooiidd (_f_u_n_c_t_i_o_n)
vvooiidd (*_f_u_n_c_t_i_o_n)();

aatteexxiitt()  registers one  or more  functions to be  called when  the program
exits.   These  registered functions  can,  for  example, perform  clean-up
beyond what  is ordinarily  performed when  a program exits.   aatteexxiitt() can
register up to 32 functions.

_f_u_n_c_t_i_o_n points to the function  to be called.  A registered function takes
no arguments and returns nothing.

The functions  that aatteexxiitt()  registers are  called when the  program exits
normally, i.e., when the function  eexxiitt() is called or when mmaaiinn() returns.
They are called in _r_e_v_e_r_s_e order of registration.

aatteexxiitt() returns  zero if _f_u_n_c_t_i_o_n  could be registered, and  a value other
than zero if it could not.

_E_x_a_m_p_l_e
This  example registers  two  functions to  be executed  upon exiting:  one
displays a message, and the other  waits for the user to press a key before
terminating.

#include <stdlib.h>
#include <stdio.h>

void
lastgasp()
{
    fprintf(stderr, "Type return to continue");
}

void
get1()
{
    getchar();
}

main()
{
    /* set up get1() as last exit routine */
    atexit(get1);
    /* set up lastgasp() as exit routine */
    atexit(lastgasp);

    /* exit, which invokes exit routines */
    exit(EXIT_SUCCESS);
}

_S_e_e _A_l_s_o
eexxiitt(), lliibbcc
ANSI Standard, section 7.10.4.2
